<%
Response.Buffer = True 
Server.ScriptTimeOut=999999
Response.Expires = -1
Response.ExpiresAbsolute = Now() - 1 
Response.Expires = 0 
Response.CacheControl = "no-cache"
response.Charset="gb2312"
%>
<!--#include file="../inc/config.asp"-->
<!--#include file="../inc/conn.asp"-->
<!-- #include file="inc/Session.asp" -->
<!--#include file="inc/collectfunc.asp"-->
<!-- #include file="inc/SaveRemoteFile.asp" -->
<!-- #include file="inc/checkrole.asp" -->
<!-- #include file="inc/function.asp" -->
<html>
<head>
<title>采集管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="style/global.css" rel="stylesheet" type="text/css">
</head>

<body>
<%
'=====================================================
'函数：getInfoTypeTitle(id)
'作用：获得信息类别名称
''''''''''''''''''''''''''''''''''''''''''''''''''''''
function GetTableTitle(id,tbl)
	dim rs
	Set rs = conn.Execute("select title from "&tbl&" where id="&id)
	if not rs.eof then
		GetTableTitle=rs(0)
	else
		GetTableTitle="null"
	end if
	rs.close
	set rs=nothing
end function

Function GetNum(strHTML3) 
	Dim objRegExp3, Match3, Matches3 ,temp3
	Set objRegExp3=New Regexp 
	objRegExp3.IgnoreCase = True 
	objRegExp3.Global = True 
	'获得字符中的链接 
	objRegExp3.Pattern ="(\d)+\.*(\d)+"
	'进行匹配 
	Set Matches3=objRegExp3.Execute(strHTML3) 
	
	' 遍历匹配集合，并替换掉匹配的项目 
	For Each Match3 in Matches3 
		temp3=trim(Match3.Value)
	Next 	
	Set objRegExp3 = Nothing 
	set Matches3=nothing
	if(temp3<>"") then
		GetNum=Clng(temp3)
	else
	GetNum=0
	end if
End Function 


response.Write("<p align=""center"">采集进行中.........</p>")
response.flush()
dim id,rs,cartoon_path,dayfolder,news_cont,templateid,parentid,infotitle,isdebug,Sts

cartoon_path="/pic"
templateid=1
dayfolder=chan_data(now())&chan_day(now())
dim Title,CategoryId,ListStart,ListEnd,PageRegx,PageNum,RelateUrl,AbsoluteUrl
dim TitleStart,TitleEnd,WylxStart,WylxEnd,PriceStart,PriceEnd,AddressStart,AddressEnd,PhotoStart,PhotoEnd,ContentStart,ContentEnd
dim AreaStart,AreaEnd,TrafficStart,TrafficEnd,FloorLevelStart,FloorLevelEnd,ContactManStart,ContactManEnd,TelStart,TelEnd,MianJiStart,MianJiEnd,HuXingStart,HuXingEnd,PriceUnit,Filters
PriceUnit="元"
	id=Clng(request.QueryString("id"))
	set rs=conn.execute("select * from t_gather_esf where id="&id)
	if not rs.eof then
		Title=rs("Title")
		CategoryId=rs("CategoryId")
		ListStart=rs("ListStart")
		ListEnd=rs("ListEnd")
		PageRegx=rs("PageRegx")
		PageNum=rs("PageNum")
		RelateUrl=rs("RelateUrl")
		AbsoluteUrl=rs("AbsoluteUrl")
		''''''''''''''''''''''''''''''''
		TitleStart=rs("TitleStart")
		TitleEnd=rs("TitleEnd")
		WylxStart=rs("WylxStart")
		WylxEnd=rs("WylxEnd")
		PriceStart=rs("PriceStart")
		PriceEnd=rs("PriceEnd")
		AddressStart=rs("AddressStart")
		AddressEnd=rs("AddressEnd")
		PhotoStart=rs("PhotoStart")
		PhotoEnd=rs("PhotoEnd")
		ContentStart=rs("ContentStart")
		ContentEnd=rs("ContentEnd")
		''''''''''''''''''''''''''
		AreaStart=rs("AreaStart")
		AreaEnd=rs("AreaEnd")
		TrafficStart=rs("TrafficStart")
		TrafficEnd=rs("TrafficEnd")
		FloorLevelStart=rs("FloorLevelStart")
		FloorLevelEnd=rs("FloorLevelEnd")
		ContactManStart=rs("ContactManStart")
		ContactManEnd=rs("ContactManEnd")
		TelStart=rs("TelStart")
		TelEnd=rs("TelEnd")
		MianJiStart=rs("MianJiStart")
		MianJiEnd=rs("MianJiEnd")
		HuXingStart=rs("HuXingStart")
		HuXingEnd=rs("HuXingEnd")
		Sts=rs("Sts")
		Filters=rs("Filters")
	end if
	rs.close
	set rs=nothing
	if(sts=0) then
		isdebug=true
	elseif(sts=1) then
		isdebug=false
	end if
	infotitle=GetTableTitle(CategoryId,"t_2infotype")
	if(CategoryId=2) then
		PriceUnit="万"&PriceUnit
	end if
	'随机数
	Randomize timer
	zNum = cint(8999*Rnd+1000)
	tempid=dayfolder&zNum
	'当天文件夹
	call MakeDir(server.MapPath(cartoon_path&"/"&dayfolder&"/"))
	dim liststr,listlink,getContent,curl,getHtml,img_saveurl,r_file,r_ext,LinkArr,s_html
	dim f_title,f_wylx,f_price,f_address,f_photo,f_content
	dim f_area,f_traffic,f_floorlevel,f_contactman,f_tel,f_mainji,f_huxing
	
	'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
	'分页开始
	'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
	dim total
	total=1
	for j=1 to PageNum
		curl=replace(PageRegx,"$num$",j)
		'''''''''''''''''''''''''''''''''''''''''''''''''''
		'if(j=3) then
			response.Write("开始采集列表页："&curl&"<hr>")
			getHtml=ReadHtml(curl,"gb2312")			
			liststr=GetBody(getHtml,ListStart,ListEnd,false,false)
			if(RelateUrl<>"" and AbsoluteUrl<>"") then
				liststr=replace(liststr,RelateUrl,AbsoluteUrl)
			end if
			listlink=GetLink(liststr)
			LinkArr=split(listlink,"|") '获得链接地址数组
			if(isdebug) then
				response.Write("链接："&listlink)
			end if
			for i=0 to ubound(LinkArr)
				if(Filters<>"" and instr(LinkArr(i),Filters)>0) then
					LinkArr(i)=""
				end if
				if(instr(LinkArr(i),"http://")>0) then
				
					response.Write("采集："&LinkArr(i)&"<br>")
					s_html=ReadHtml(LinkArr(i),"gb2312")
					f_title=RemoveHTML(GetBody(s_html,TitleStart,TitleEnd,false,false))
					f_wylx=RemoveHTML(GetBody(s_html,WylxStart,WylxEnd,false,false))
					f_price=RemoveHTML(GetBody(s_html,PriceStart,PriceEnd,false,false))
					f_address=RemoveHTML(GetBody(s_html,AddressStart,AddressEnd,false,false))
					'f_photo="http://house.0518home.com"&GetBody(s_html,PhotoStart,PhotoEnd,false,false)
					'img_saveurl="/pic/"&dayfolder&"/lp_"&total&".jpg"
					f_content=RemoveHTML(GetBody(s_html,ContentStart,ContentEnd,false,false))
					'''''''''''''''''''''''''''''''''''''''''''''''''''''''
					f_area=RemoveHTML(GetBody(s_html,AreaStart,AreaEnd,false,false))
					f_traffic=RemoveHTML(GetBody(s_html,TrafficStart,TrafficEnd,false,false))
					f_floorlevel=RemoveHTML(GetBody(s_html,FloorLevelStart,FloorLevelEnd,false,false))
					f_contactman=RemoveHTML(GetBody(s_html,ContactManStart,ContactManEnd,false,false))
					if(f_contactman<>"") then 
					else f_contactman="" 
					end if
					f_tel=RemoveHTML(GetBody(s_html,TelStart,TelEnd,false,false))
					f_mainji=RemoveHTML(GetBody(s_html,MianJiStart,MianJiEnd,false,false))
					f_huxing=RemoveHTML(GetBody(s_html,HuXingStart,HuXingEnd,false,false))
					if(isdebug) then
						response.Write("标题："&f_title&"<br>")
						response.Write("物业类型："&f_wylx&"<br>")
						response.Write("价格："&f_price&"<br>")
						response.Write("地址："&f_address&"<br>")
						response.Write("图："&f_photo&":"&img_saveurl&"<br>")
						response.Write("地区："&f_area&"<br>")
						response.Write("楼层："&f_floorlevel&"<br>")
						response.Write("联系人："&f_contactman&"<br>")
						response.Write("电话："&f_tel&"<br>")
						response.Write("面积："&f_mainji&"<br>")
						response.Write("户型："&f_huxing&"<br>")
						response.Write("交通："&f_traffic&"<br>")
						response.Write("内容："&f_content&"<br>")
						response.Write("价格："&GetNum(f_price)&"<br>")
						response.Write("<hr />")					
					end if
					response.Write("成功采集："&f_title&"<br>")
					response.Flush()
					'''''''''''''''''''''''				
					'call saveimage(f_photo,server.MapPath(img_saveurl))
					if(isdebug) then
						response.Write("测试状态，数据采集不入库")
					else
						set rs=server.createobject("adodb.recordset")
						rs.open "select top 1 * from t_2house where 1=0 order by id desc ",conn,3,3
						rs.addnew
						rs("UserId")=""
						rs("InfoTypeId")=CategoryId
						rs("AreaId")=1
						rs("RoomTypeId")=1
						rs("FloorLevelId")=1
						rs("InfoTypeTitle")=infotitle
						rs("AreaTitle")=f_area
						rs("RoomTypeTitle")=f_huxing
						rs("FloorLevelTitle")=f_floorlevel
						rs("Acreage")=GetNum(f_mainji)
						rs("Price")=GetNum(f_price)
						rs("PriceUnit")=PriceUnit
						rs("Address")=f_address
						rs("ContactMan")=f_contactman
						rs("ContactType")=f_tel
						rs("OtherDes")=f_content
						rs("IsCheck")=0
						rs("UserIp")=""
						rs("ModiTime")=now()
						rs("Hits")=0
						rs("HouseType")=1
						rs("DelPass")="* *"
						rs("SexDemond")=""
						rs("MapX")=0
						rs("MapY")=0
						rs("MapZ")=0
						rs("Photo")=img_saveurl
						rs("Bus")=f_traffic
						rs("IsRecommend")=0
						rs("PubBy")=0
						rs.update
						rs.close
						set rs=nothing
					end if
					'结束采集详细页
					i=i+1
					total=total+1
				end if				
			next
			'一页采集完
		'''''''''''''''''''''''''''''''''''''''''''''''''
	next'分页结束
		
	response.Write("<p align=""center"">成功采集，[采集完成,共采集"&total&"条数据].........</p>")
call connclose()
%>