def docLisPageContentLoad(url:String):String={
//获取Html文档内容
val htm=HtmlDocLoader
var htmlContent=htm.getPageByURLConnetion(url,"GBK")
// println(htmlContent)
//提取其它数据
htmlContent
}
//list page info
def listPageInfoParse(htmlContent:String): Map[String,String] ={
//通过正则表达式提取广告
//创建Html文档分析器
val htmlParse=HtmlDocParser
//提取数据测试
val html_title=htmlParse.parsehtmlTitle(htmlContent)
//html keyword
//html description
//body
//cn text
var listpageinfoMap=Map[String,String]()
// listpageinfoMap.put("html_title" , html_title)
// listpageinfoMap.put("html_content",htmlContent.asInstanceOf[String])
def parseCompany(codeblock:String): Map[String,String] ={
println("Ali Company Info parse:")
// is cyt
val isadcmp=isadCmpinfo(codeblock)
var entryMap=Map[String,String]()
println ("is cyt cmp:"+isadcmp )
if(isadcmp==true){
//test link
val adlinkcode=parseadlinkCode(codeblock)
println("cmp link code "+adlinkcode.length)
//cmp link
val cmp_link=parseAdLink(adlinkcode)
println("cmp link parse:"+cmp_link.length)
//cmp name
val cmp_name=parseadcmpName(adlinkcode)
def count= {
var countvl:Long =0
DB.withConnection { implicit c =>
val firstRow = SQL("Select count(*) as c from ad_spider_info").apply().head
val countryCount = firstRow[Long]("c")
// println("count:" + countryCount)
countvl=countryCount
}
countvl
}
//add data
//test : ok
def add(e:AdSpiderInfo):Boolean = {
val rs= SQL(
"""update
ad_spider_info set urlPath={urlPath}, comFrome={comFrome},addTime={addTime},updateTime={updateTime} where infoid={infoid}
""")
.on(
"urlPath"->e.urlPath,
"comFrome"->e.comForm,
"addTime"->e.addTime,
"updateTime"->e.updateTime,
"id"->e.infoid
)
.executeUpdate()
rs == 1
}
}
def delete(infoid:Long):Boolean = {
DB.withConnection {implicit c =>
val rs= SQL(
"""delete from ad_spider_info where infoid={infoid}
""")
.on(
"id"->infoid
)
.executeUpdate()
rs == 0
}
}
/*
*/
//query ad
def getAdById(infoid: Long): AdSpiderInfoView = {
var adSpiderInfo:AdSpiderInfoView=null
DB.withConnection { implicit conn =>
val sql: SqlQuery = SQL("Select * from ad_spider_info where infoid={infoid} order by infoid desc")
sql .on( "infoid"-> infoid)
//var infoid :Long, var urlPath:String,
//var addTime:Date,var visitSalerId:Long, var visitSaler:String, var comForm:String, var updateTime:Date
val list:List[AdSpiderInfoView]= sql().map(row =>
AdSpiderInfoView(row[Long]("infoid"), row[String]("urlPath")
,row[Long]("visitSalerId"),
row[String]("visitSaler"),row[String]("comForm"),row[Date]("updateTime"), row[Date]("addTime"))
).toList
val sql = SQL("Select * from ad_spider_info where urlPath = {urlpath} order by infoid desc")
.on( "urlpath" -> urlpath)
//var infoid :Long, var urlPath:String,
//var addTime:Date,var visitSalerId:Long, var visitSaler:String, var comForm:String, var updateTime:Date
val sql: SimpleSql[Row] = SQL("Select * from ad_spider_info limit {start}, {pageCount} where comForm={comForm}")
.on(
"start"->start,
"pageCount"->pageCount,
"comForm"->comForm
)
//var infoid :Long, var urlPath:String,
//var addTime:Date,var visitSalerId:Long, var visitSaler:String, var comForm:String, var updateTime:Date
val list:List[AdSpiderInfoView]= sql().map(row =>
AdSpiderInfoView(row[Long]("infoid"), row[String]("urlPath")
,row[Long]("visitSalerId"),
row[String]("visitSaler"),row[String]("comForm"), row[Date]("addTime"),row[Date]("updateTime"))
).toList
adSpiderInfolist= list
}
adSpiderInfolist
}
def getListAll(): List[AdSpiderInfoView]= {
var adSpiderInfolist: List[AdSpiderInfoView]=null
DB.withConnection { implicit c =>
val sql: SqlQuery = SQL("Select * from ad_spider_info order by infoid desc")
//var infoid :Long, var urlPath:String,
//var addTime:Date,var visitSalerId:Long, var visitSaler:String, var comForm:String, var updateTime:Date
val list: List[AdSpiderInfoView] = sql().map(row =>
AdSpiderInfoView(row[Long]("infoid"), row[String]("urlPath")
, row[Long]("visitSalerId"),
row[String]("visitSaler"), row[String]("comForm"), row[Date]("addTime"), row[Date]("updateTime"))
).toList
adSpiderInfolist = list
}
adSpiderInfolist
}
def main (argvs:Array [String]){
var ifo=new AdSpiderInfo()
ifo.urlPath="http://aabbcc.com/test.html"