<!--#include file="../inc/config.asp"-->
<!--#include file="../inc/conn.asp"-->
<!-- #include file="inc/Session.asp" -->
<!--#include file="inc/collectfunc.asp"-->
<!-- #include file="inc/checkrole.asp" -->
<%
Server.ScriptTimeout = 999999
'''''''''''''''''''''''''''''''''''''''''''''''
call checkPrevilege(Session("Name"),"p09")
'''''''''''''''''''''''''''''''''''''''''''''''
BeginTime=Timer
dim taskid
if not isempty(request("taskid")) then 
	taskid=Cint(request("taskid"))
else
	taskid=0
end if
dim StartUrl,ListStartTag,ListEndTag,PageSplitTag,StartPageNum,EndPageNum,encode,taskname,catalogid,CollectNum
StartUrl=request.Form("StartUrl")
if(StartUrl="" or len(StartUrl)<1) then
	response.Write("错误!开始网址不能为空!")
	response.Write("&nbsp;&nbsp;<a href=""#"" onClick=""javascript:history.back();""><==返回</a>")
	response.End()
end if
ListStartTag=request.Form("ListStartTag")
if(ListStartTag="" or len(ListStartTag)<1) then
	response.Write("错误!列表开始标记不能为空!")
	response.Write("&nbsp;&nbsp;<a href=""#"" onClick=""javascript:history.back();""><==返回</a>")
	response.End()
end if
ListEndTag=request.Form("ListEndTag")
if(ListEndTag="" or len(ListEndTag)<1) then
	response.Write("错误!列表结束标记不能为空!")
	response.Write("&nbsp;&nbsp;<a href=""#"" onClick=""javascript:history.back();""><==返回</a>")
	response.End()
end if
encode=trim(request.Form("encode"))
if(encode="" or len(encode)<1) then
	response.Write("错误!编码不能为空!")
	response.Write("&nbsp;&nbsp;<a href=""#"" onClick=""javascript:history.back();""><==返回</a>")
	response.End()
end if
taskname=trim(request.Form("taskname"))
if(taskname="" or len(taskname)<1) then
	response.Write("错误!任务名称不能为空!")
	response.Write("&nbsp;&nbsp;<a href=""#"" onClick=""javascript:history.back();""><==返回</a>")
	response.End()
end if
catalogid=Cint(request.Form("catalogid"))
if(request.Form("CollectNum")<>"") then
	CollectNum=Cint(request.Form("CollectNum"))	
else
	CollectNum=0
end if
application.Lock()
application(taskname&"_CollectNum")=CollectNum
application.UnLock()
%>
<html>
<head>
<title>信息采集</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	background-color: #D4D0C8;
}
input{ font-size:12px;}
form{margin:0;}
-->
</style>
<link href="../admin/cs.css" rel="stylesheet" type="text/css">
<style type="text/css">
body{font-size:12px;}
<!--
.style1 {color: #FF0000}
.style2 {color: #CCCCCC}
.style3 {color: #FFFFFF;
	font-weight: bold;
}
-->
</style>
</head>
<body>
<table width="100%"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><iframe src="right_top.htm" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" height="30" width="100%"></iframe></td>
  </tr>
</table>
<table width="100%"  border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#999999">
  <tr bgcolor="#FF9900">
    <td width="100%" height="22"><div align="center"><span class="style3">◆ 信息采集 ◆</span></div></td>
  </tr>
</table>
<!--开始采集规则-->
<!--开如数据设置规则-->
<fieldset style="margin:5px 50px 5px 50px; border-top:1px solid #ffffff; border-right:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #ffffff;">
<%
if(taskid>=1) then
	set rs=server.CreateObject("adodb.recordset") 
	rs.open "select top 1 * from collect where id="&taskid,conn,3,3
	if not rs.eof then
%>
	<form name="form1" method="post" action="collect4.asp">
	  <legend>第三步设置数据提取规则</legend>
	<table width="100%"  border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="35%"><div align="right">解析方式：</div></td>
    <td width="65%"><div align="left">
      <input name="ParseType" type="radio" value="0" <%if(rs("ParseType")=0) then response.Write("checked")%>>
      
    解析源文件
    <input name="ParseType" type="radio" value="1" <%if(rs("ParseType")=1) then response.Write("checked")%>>
    解析页面数据(即去除所有HTML源代码后的数据)
    </div></td>
    </tr>
  <tr>
    <td><div align="right">标题起始标记：</div></td>
    <td><div align="left">
      <textarea name="TitleStartTag" cols="50" rows="6" id="TitleStartTag"><%=rs("TitleStartTag")%></textarea>
</div></td>
  </tr>
  <tr>
    <td><div align="right">标题结束标记：</div></td>
    <td><div align="left">
      <textarea name="TitleEndTag" cols="50" rows="6" id="TitleEndTag"><%=rs("TitleEndTag")%></textarea>
    </div></td>
  </tr>
  <tr>
    <td><div align="right">新闻内容起始标记：</div></td>
    <td><div align="left">
      <textarea name="ContentStartTag" cols="50" rows="6" id="ContentStartTag"><%=rs("ContentStartTag")%></textarea>
    </div></td>
  </tr>
  <tr>
    <td><div align="right">新闻内容结束标记：</div></td>
    <td><div align="left">
      <textarea name="ContentEndTag" cols="50" rows="6" id="ContentEndTag"><%=rs("ContentEndTag")%></textarea>
    </div></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td height="50">
	<input type="hidden" name="taskid" value="<%=taskid%>">
	<input type="hidden" name="encode" value="<%=encode%>">
	<input type="hidden" name="taskname" value="<%=taskname%>">
	<input type="hidden" name="catalogid" value="<%=catalogid%>">
	<input type="submit" name="Submit32" value="下一步" onClick="Layer1.style.display=''">
      <input type="button" name="btn" value="返  回" onClick="javascript:history.go(-1);"></td>
  </tr>
</table>
</form>
<%
	end if
	rs.close
	set rs=nothing
else
%>
	<form name="form1" method="post" action="collect4.asp">
	  <legend>第三步设置数据提取规则</legend>
	<table width="100%"  border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="35%"><div align="right">解析方式：</div></td>
    <td width="65%"><div align="left">
      <input name="ParseType" type="radio" value="0" checked>
      
    解析源文件
    <input name="ParseType" type="radio" value="1">
    解析页面数据(即去除所有HTML源代码后的数据)
    </div></td>
    </tr>
  <tr>
    <td><div align="right">标题起始标记：</div></td>
    <td><div align="left">
      <textarea name="TitleStartTag" cols="50" rows="6" id="TitleStartTag"></textarea>
</div></td>
  </tr>
  <tr>
    <td><div align="right">标题结束标记：</div></td>
    <td><div align="left">
      <textarea name="TitleEndTag" cols="50" rows="6" id="TitleEndTag"></textarea>
    </div></td>
  </tr>
  <tr>
    <td><div align="right">新闻内容起始标记：</div></td>
    <td><div align="left">
      <textarea name="ContentStartTag" cols="50" rows="6" id="ContentStartTag"></textarea>
    </div></td>
  </tr>
  <tr>
    <td><div align="right">新闻内容结束标记：</div></td>
    <td><div align="left">
      <textarea name="ContentEndTag" cols="50" rows="6" id="ContentEndTag"></textarea>
    </div></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td height="50">
	<input type="hidden" name="encode" value="<%=encode%>">
	<input type="hidden" name="taskname" value="<%=taskname%>">
	<input type="hidden" name="catalogid" value="<%=catalogid%>">
	<input type="submit" name="Submit32" value="下一步">
      <input type="button" name="btn" value="返  回" onClick="javascript:history.go(-1);"></td>
  </tr>
</table>
</form>
<%end if%>
</fieldset>
<!--以下是采集地址的内容-->
<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;">
<legend>以下是采集到的链接地址</legend>
<%
'==========================================================================
'						定义变量&获得参数
'==========================================================================
dim LinkSet,LinkFrom,LinkTo,RemoveLinkStr,LinkTemp,LinkArr,RemoveLinkArr
LinkSet=Cint(request.Form("LinkSet"))
LinkFrom=Trim(request.Form("LinkFrom"))
LinkTo=Trim(request.Form("LinkTo"))
RemoveLinkStr=trim(request.Form("removelinkstr"))
PageSplitTag=trim(request.Form("PageSplitTag"))
if(request.Form("StartPageNum")<>"") then
	StartPageNum=Cint(request.Form("StartPageNum"))
end if
if(request.Form("EndPageNum")<>"") then
	EndPageNum=Cint(request.Form("EndPageNum"))
end if
if(taskid>=1) then
'======================================
'修改采集规则到库
'======================================
	set rs=server.CreateObject("adodb.recordset") 
	rs.open "select top 1 * from collect where id="&taskid,conn,3,3
	if not rs.eof then
		rs("StartUrl")=StartUrl
		rs("ListStartTag")=ListStartTag
		rs("ListEndTag")=ListEndTag
		rs("LinkSet")=LinkSet
		rs("LinkFrom")=LinkFrom
		rs("LinkTo")=LinkTo
		rs("removelinkstr")=removelinkstr
		rs("PageSplitTag")=PageSplitTag
		rs("StartPageNum")=StartPageNum
		rs("EndPageNum")=EndPageNum
		rs("CollectNum")=CollectNum
		rs.update
		rs.close
		set rs=nothing
	else
		response.Write("没有找到ID为"&taskid&"的任务")
		response.End()
	end if
else
'======================================
'添加采集规则到库
'======================================
	set rs=server.CreateObject("adodb.recordset") 
	rs.open "select top 1 * from collect where TaskName='"&taskname&"'",conn,3,3
	if not rs.eof then
		rs("StartUrl")=StartUrl
		rs("ListStartTag")=ListStartTag
		rs("ListEndTag")=ListEndTag
		rs("LinkSet")=LinkSet
		rs("LinkFrom")=LinkFrom
		rs("LinkTo")=LinkTo
		rs("removelinkstr")=removelinkstr
		rs("PageSplitTag")=PageSplitTag
		rs("StartPageNum")=StartPageNum
		rs("EndPageNum")=EndPageNum
		rs("CollectNum")=CollectNum
		rs.update
		rs.close
		set rs=nothing
	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	
	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
if(cint(application(taskname&"_CollectNum"))=0) then
	application(taskname&"_CollectNum")=ubound(LinkArr)
end if
'test
application.Lock()
application(taskname)=LinkArr
application.UnLock()
testa=application(taskname)
dim iii
iii=0
for ii=0 to ubound(testa)
	if(testa(ii)<>"") then		
		if(iii>=cint(application(taskname&"_CollectNum"))) then
			exit for
		end if
		response.Write(testa(ii)&"<br>")
		iii=iii+1
	end if
next
%>
</fieldset>
<p align="center"><%=CStr(FormatNumber((Timer-BeginTime)*1000,2))& "毫秒"%></p>
<div id="Layer1" style="position:absolute; display:none; width:285px; height:159px; z-index:1; left: 447px; top: 381px; background-color: #003399; layer-background-color: #99FFFF; border: 1px none #000000;">
  <div align="center">
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p><font color="#FFFFFF">信息采集中，可能时间比较长请耐心等待...</font></p>
  </div>
</div>
</body>
</html>
<%call connclose()%>