<%
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>
<%
response.End()
response.Write("<p align=""center"">采集进行中.........</p>")
response.flush()
dim id,rs,cartoon_path,dayfolder,news_cont,templateid,parentid
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	
	id=Clng(request.QueryString("id"))
	set rs=conn.execute("select * from t_gather_lp 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")
	end if
	rs.close
	set rs=nothing
		
	'随机数
	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 total
	total=0
	for j=1 to PageNum
		curl=replace(PageRegx,"$num$",j)
		'''''''''''''''''''''''''''''''''''''''''''''''''''
		'if(j=3) then
			getHtml=ReadHtml(curl,"utf-8")			
			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,"|") '获得链接地址数组
			for i=0 to ubound(LinkArr)
				if(instr(LinkArr(i),"items")>0 ) then
					'response.Write(LinkArr(i)&"<br>")
					s_html=ReadHtml(LinkArr(i),"utf-8")
					f_title=GetBody(s_html,TitleStart,TitleEnd,false,false)
					f_wylx=GetBody(s_html,WylxStart,WylxEnd,false,false)
					f_price=GetBody(s_html,PriceStart,PriceEnd,false,false)
					f_address=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=GetBody(s_html,ContentStart,ContentEnd,false,false)
					response.Write("标题："&f_title)
					response.Write("物业类型："&f_wylx)
					response.Write("价格："&f_price)
					response.Write("地址："&f_address)
					response.Write("图："&f_photo&":"&img_saveurl)
					response.Write("内容："&f_content)
					response.Flush()
					'''''''''''''''''''''''
					'开始采集详细页					
					call saveimage(f_photo,server.MapPath(img_saveurl))
					set rs=server.createobject("adodb.recordset")
					rs.open "select top 1 * from t_lp where Title='"&f_title&"' order by id desc ",conn,3,3
					if not rs.eof then
					else		
						rs.addnew
						rs("Title")=f_title		
						rs("Photo")=img_saveurl
						rs("LpTypeId")=0
						rs("LpAreaId")=0
						rs("f_jzlb")=f_wylx
						rs("f_minprice")=f_price
						rs("f_price")=f_price
						rs("f_maxprice")=f_price
						rs("f_zxqk")=""
						rs("f_jtwz")=""
						rs("f_kpsj")=""
						rs("f_rzsj")=""
						rs("f_jylb")=""
						rs("f_fkfs")=""
						rs("f_wydz")=f_address
						rs("f_qclx")=""
						rs("f_xsxk")=""
						rs("f_kfs")=""
						rs("f_sldz")=f_address
						rs("f_sldh")=""
						rs("f_desc")=f_content
						rs("f_wy_zdmj")=""
						rs("f_wy_jzmj")=""
						rs("f_wy_lhl")=""
						rs("f_wy_rjl")=""
						rs("f_wy_dt")=""
						rs("f_wy_cw")=""
						rs("f_wy_wygs")=""
						rs("f_wy_wyf")=""
						rs("f_wy_zfs")=""
						rs("f_wy_sgjd")=""
						rs("f_ptss_zb")=""
						rs("f_ptss_jc")=""
						rs("f_date")=now	
						rs("f_hits")=1
						rs("f_type_title")=""
						rs("f_area_title")=""
						rs("f_price_unit")="元/平方米"
						rs("f_traffic_pic")=""
						rs("f_mapx")=0
						rs("f_mapy")=0
						rs("f_mapz")=0
						rs("f_char")=""
						rs("f_bbsurl")=""
						rs.update	
					end if
					rs.close
					set rs=nothing
					'结束采集详细页
					i=i+3
					total=total+1
				end if				
			next
			'response.End()
		'end if
		'''''''''''''''''''''''''''''''''''''''''''''''''
	next'分页结束
	response.Write(news_cont)
	'结束
	
	response.Write("<p align=""center"">成功采集，[采集完成].........</p>")
call connclose()
%>