<!--#include file="../inc/config.asp"-->
<!--#include file="../inc/conn.asp"-->
<!-- #include file="inc/Session.asp" -->
<!-- #include file="inc/checkrole.asp" -->
<!--#include file="inc/collectfunc.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>信息采集</title>
</head>
<body>
<%
'''''''''''''''''''''''''''''''''''''''''''''''
call checkPrevilege(Session("Name"),"p09")
'''''''''''''''''''''''''''''''''''''''''''''''
dim TaskName,CollectUrl,Encode,IfLogin,LoginUrl,LoginActUrl,PostData,LoginFailMsg,CatalogId,StartUrl,ListStartTag,ListEndTag
dim LinkSet,LinkFrom,LinkTo,removelinkstr,PageSplitTag,StartPageNum,EndPageNum,ParseType,TitleStartTag,TitleEndTag,ContentStartTag,ContentEndTag,ContentLinkStart,ContentLinkEnd,DomainUrl
dim loginback,LinkTemp,pageII,LinkArr,RemoveLinkArr
BeginTime=Timer
dim taskid
if not isempty(request("taskid")) then 
	taskid=Cint(request("taskid"))
else
	response.Write("<script>alert(""没有要采集的项目"");history.back();</script>")
	response.End()
end if

if(taskid>=1) then
	set rs=server.CreateObject("adodb.recordset") 
	rs.open "select top 1 * from collect where id="&taskid,conn,3,1
	if not rs.eof then
		TaskName=rs("TaskName")
		CollectUrl=rs("CollectUrl")
		Encode=rs("Encode")
		IfLogin=rs("IfLogin")
		LoginUrl=rs("LoginUrl")
		LoginActUrl=rs("LoginActUrl")
		PostData=rs("PostData")
		LoginFailMsg=rs("LoginFailMsg")
		CatalogId=rs("CatalogId")
		StartUrl=rs("StartUrl")
		ListStartTag=rs("ListStartTag")
		ListEndTag=rs("ListEndTag")
		LinkSet=rs("LinkSet")
		LinkFrom=rs("LinkFrom")
		LinkTo=rs("LinkTo")
		removelinkstr=rs("removelinkstr")
		PageSplitTag=rs("PageSplitTag")
		StartPageNum=rs("StartPageNum")
		EndPageNum=rs("EndPageNum")
		ParseType=rs("ParseType")
		TitleStartTag=rs("TitleStartTag")
		TitleEndTag=rs("TitleEndTag")
		ContentStartTag=rs("ContentStartTag")
		ContentEndTag=rs("ContentEndTag")
		ContentLinkStart=rs("ContentLinkStart")
		ContentLinkEnd=rs("ContentLinkEnd")
		rs.close
		set rs=nothing
		'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
		'添加缓存
		'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
		application.Lock()
		application("Encode")=Encode	
		application("CatalogId")=CatalogId	
		application("ParseType")=ParseType	
		application("TitleStartTag")=TitleStartTag	
		application("TitleEndTag")=TitleEndTag	
		application("ContentStartTag")=ContentStartTag
		application("ContentEndTag")=ContentEndTag
		application("ContentLinkStart")=ContentLinkStart
		application("ContentLinkEnd")=ContentLinkEnd
		application("CollectUrl")=CollectUrl
		application.UnLock()
		'response.Write("Encode:"&application("Encode")&"<br>"&Chr(10))
		'response.Write("ParseType:"&application("ParseType")&"<br>"&Chr(10))
		'response.Write("TitleStartTag:"&TitleStartTag&"<br>"&Chr(10))
		'response.Write("TitleEndTag:"&application("TitleEndTag")&"<br>"&Chr(10))
		'response.Write("ContentStartTag:"&application("ContentStartTag")&"<br>"&Chr(10))
		'response.Write("ContentEndTag:"&application("ContentEndTag")&"<br>"&Chr(10))
		'response.Write("ContentLinkStart:"&application("ContentLinkStart")&"<br>"&Chr(10))
		'response.Write("ContentLinkEnd:"&application("ContentLinkEnd")&"<br>"&Chr(10))
		'response.Write("CollectUrl:"&application("CollectUrl")&"<br>"&Chr(10))
		''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
	else
		response.Write("<script>alert(""没有找到要采集的项目"");</script>")
		rs.close
		set rs=nothing
		call connclose()
		response.End()
	end if
	DomainUrl=CollectUrl
	DomainUrl=replace(DomainUrl,"http://","")
	DomainUrl=left(DomainUrl,instr(DomainUrl,"/"))
	'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
	'如果需要登录
	'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
	if(IfLogin=1) then
		loginback=PostHttpPage(LoginUrl,LoginActUrl,PostData) 
		if(instr(loginback,LoginFailMsg)>0) then
			response.Write("登录失败，请重新设置登录参数！")
			response.Write("&nbsp;&nbsp;<a href=""#"" onClick=""javascript:history.back();""><==返回</a>")
			call connclose()
			response.End()
		else
			response.Write("登录成功，系统继续执行.....<br>")
		end if
	end if
	'==========================================================================
	'设置分页标记
	'==========================================================================
	if(PageSplitTag="") then
		LinkTemp=GetLink(ReadXml(StartUrl,encode,ListStartTag,ListEndTag))
	else
		for pageII=StartPageNum to EndPageNum
			dim tempPage		
			tempPage=GetLink(GetBody(ReadHtml(replace(PageSplitTag,"$NUM$",pageII),encode),ListStartTag,ListEndTag,false,false))		
			LinkTemp=LinkTemp&tempPage
		next	
	end if
	'==========================================================================
	'						替换成绝对链接地址
	'==========================================================================
	if(LinkSet=0)then

	else
		LinkTemp=replace(LinkTemp,LinkFrom,LinkTo)'替换成绝对链接地址	
	end if
	'==========================================================================
	'						过滤无用的链接字符
	'==========================================================================
	if(RemoveLinkStr<>"") then
	dim i,j
		LinkArr=split(LinkTemp,"|") '获得链接地址数组
		RemoveLinkArr=split(RemoveLinkStr,"|")	'获得要过滤掉的链接字符数组	
		If IsArray(LinkArr)=True Then		
			for i=0 to ubound(LinkArr)		
				for j=0 to ubound(RemoveLinkArr)			
					if(instr(LinkArr(i),RemoveLinkArr(j))<>0) then
						LinkArr(i)=""
					else
					
					end if
				next			
			next
		end if
	else
		LinkArr=split(LinkTemp,"|") '获得链接地址数组
	end if
	'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
	'添加链接地址到历史库
	'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
	response.Write("<fieldset style=""margin:5px 50px 5px 50px; padding:10px; border-top:1px solid #ffffff; border-right:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #ffffff;"">"&Chr(10))
	response.Write("<legend>以下是采集到的新闻地址</legend>"&Chr(10))
	response.Write("<textarea name=""textarea"" cols=""80"" rows=""10"">"&Chr(10))
	dim ofs,nlnkurl
	for ii=0 to ubound(LinkArr)-1
		ofs=ubound(LinkArr)-1-ii
		if(LinkArr(ofs)<>"") then
			nlnkurl=LinkArr(ofs)
			if(instr(nlnkurl,"http")=0) then
				nlnkurl=DomainUrl&nlnkurl
				nlnkurl="http://"&replace(nlnkurl,"//","/")				
			end if			
			'response.Write(nlnkurl)
			'response.End()
			set rs=server.CreateObject("adodb.recordset") 
			rs.open "select top 1 * from collect_his where linkurl='"&nlnkurl&"'",conn,3,3
			if rs.eof or rs.bof then
				rs.addnew
				rs("linkurl")=nlnkurl
				rs("taskid")=taskid
				rs("iscollected")=0
				rs("moditime")=now
				rs.update
			end if
			rs.close
			set rs=nothing
			response.Write(nlnkurl&Chr(10))
		end if
	next
	response.Write("</textarea"&Chr(10))
	response.Write("</fieldset>"&Chr(10))
	response.Write("<meta http-equiv=""refresh"" content=""5;URL=iscollecting.asp?taskid="&taskid&"&id=1"">"&Chr(10))
	response.Write("<br>系统将在<input type=""button"" id=""countdown"" value=""5秒"">后开始采集数据，如果您想取消操作，请点击<a href=""javascript:history.back();"">此处</a>返回链接。")
%>
<script language="javascript">
function showTime(n){
	if(n>0){		
		document.getElementById('countdown').value=n+'秒';		
	}
}
var limits=5;
for(i=limits;i>0;i--){
	window.setTimeout("showTime("+i+")",(limits-i+1)*1000);
}
</script>
<%	
end if
call connclose()
%>
</body>
</html>