<!--#include file="./Conn_Mail.asp"-->
<!--#include file="inc/Check.asp"-->
<!--#include file="inc/public.asp"-->
<!--#include File="XMLHTTP.asp"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>ELIGHT.CC</title>
</head>
<link href="Images/Admin.css" rel="stylesheet" type="text/css">
<body>
<table width="98%" height="40"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr> 
    <td><table width="100%"  border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#D8D8D8">
        <tr> 
          <td height="30" align="left" bgcolor="ffffff"><table width="100%" height="100%"  border="0" cellpadding="3" cellspacing="0">
              <tr bgcolor="eeeeee"> 
                <td width="5%" align="center"><img src="Images/1.gif" width="13" height="12"></td>
                <td width="78%"><span class="style2">管理中心 &gt;&gt;&gt; 抓取URL任务建立</span></td>
                <td width="17%" align="right">&nbsp; </td>
              </tr>
            </table></td>
        </tr>
      </table></td>
  </tr>
</table>
<table width="98%" height="90%"  border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#D8D8D8">
  <tr> 
    <td valign="top" bgcolor="ffffff"><table width="96%" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td><br> 
<%
Dim Makking
	Makking  = Trim(Request.QueryString("Makking"))
Select Case Makking
	
Case "AddTask"

	URL_A    = Request.Form("URL_A")
	URL_A_A  = Request.Form("URL_A_A")
	IF URL_A_A  = "" Then
	   URL_A_A  = 0
	End IF
	URL_A_B  = Request.Form("URL_A_B")
	IF URL_A_B  = "" Then
	   URL_A_B  = 0
	End IF
	URL_A_C  = Request.Form("URL_A_C")
	IF URL_A_C  = "" Then
	   URL_A_C  = 0
	End IF
	URL_B    = Request.Form("URL_B")
	Body_A   = Request.Form("Body_A")
	Body_B   = Request.Form("Body_B")
	Body_C   = Request.Form("Body_C")
	TaskName = Request.Form("TaskName")
	T        = Request.Form("T")
	M        = Request.Form("M")
	
	IF URL_A = "" or TaskName = "" or Body_A = "" Then
	Save_title="·请填写必要的参数"   
	call Save_Err()
	End IF
	
	Conn_m.Execute("Insert Into XMLHTTPURL (URL_A,URL_A_A,URL_A_B,URL_A_C,URL_B,Body_A,Body_B,Body_C,TaskName,T,M) values ('"& URL_A &"','"& URL_A_A &"',"& URL_A_B &","& URL_A_C &",'"& URL_B &"','"& Body_A &"','"& Body_B &"','"& Body_C &"','"& TaskName &"',"& T &","& M &")")
	
	Set Rs = Conn_m.Execute("Select Top 1 ID From XMLHTTPURL Order By ID Desc")
	
		IF Not Rs.Eof Then
	
			Conn_m.Execute("Insert Into Mail_Group (GroupName,Datetime,TaskID) Values ('"& TaskName &"','"&now&"',"& Rs("ID") &")")
		
		End IF
		
		Rs.Close
		
	Set Rs = Nothing
	
	Set Rs = Conn_m.Execute("Select Top 1 ID From XMLHTTPURL order By ID Desc")
		IF Not Rs.Eof Then
		ID = Rs("ID")
		End IF
		Rs.Close
	Set Rs = Nothing
	
	Response.Write("&nbsp;&nbsp;任务创建成功，<a href=XMLHTTPURL.asp?Makking=MakeTask&ID="& ID &" Class=home>点这里执行任务</A>")
	
Case "MakeTask"

Sub NextPage()



			IF int(URL_A_A) >= int(URL_A_C) Then

				Response.Write("完成任务")
				Response.End()
			
			Else
			
			
			
				URL_A_A = URL_A_A + URL_A_B
				
				Response.Write("完成"& URL &"<br>")
				Response.Write(BodyListStr)
				Response.Write("正在开始抓取下一页...")
				Response.Write("<meta http-equiv=""refresh"" content="""& M &";url=XMLHTTPURL.asp?Makking=MakeTask&ID="& ID &"&URL_A_A="& URL_A_A &""">")
				Response.End()
				
			End IF

End Sub

Dim URL,OpenArr,EndArr,URLBody,LenOpenArr,LenEndArr,Body

	ID = Trim(Request.QueryString("ID"))

	Set Rs = Conn_m.Execute("Select * From XMLHTTPURL Where ID = "& ID &"")
		IF Not Rs.Eof Then
		
			URL_A    = Rs("URL_A")
			
			URL_A_A  = INT(Rs("URL_A_A"))
			IF URL_A_A = "" or Not IsNumeric(URL_A_A) Then URL_A_A = 0

			URL_A_B  = INT(Rs("URL_A_B"))
			IF URL_A_B = "" or Not IsNumeric(URL_A_B) Then URL_A_B = 1

			URL_A_C  = INT(Rs("URL_A_C"))
			IF URL_A_C = "" or Not IsNumeric(URL_A_C) Then URL_A_B = 1

			URL_B    = Rs("URL_B")
			
			Body_A   = Rs("Body_A")
			Body_B   = Rs("Body_B")
			Body_C   = Rs("Body_C")
			T        = Rs("T")
			IF T = "" or Not IsNumeric(T) Then T = 1
			M        = Rs("M")
			IF M = "" or Not IsNumeric(M) Then M = 1
			TaskID   = Rs("TaskID")
		
		End IF
		Rs.Close
	Set Rs = Nothing
	
					IF Trim(Request.QueryString("URL_A_A"))<>"" Then
					
						URL_A_A = INT(Trim(Request.QueryString("URL_A_A")))
										
					End IF
					
					IStr = 0
					
					IF Trim(Request.QueryString("IStr"))<>"" Then
					
						IStr = INT(Trim(Request.QueryString("IStr")))
										
					End IF
					
					IF Trim(Request.QueryString("LenOpen"))<>"" Then
					
						LenOpen = Trim(Request.QueryString("LenOpen"))
					
					Else
					
					LenOpen = 1
					
					End IF
					
					URL        = URL_A & URL_A_A & URL_B

	For i = 1 to T
	
		Body_A = Split(Body_A,",")
		Body_B = Split(Body_B,",")
		BodyList   = ""
		
			For  n = 0 to ubound(Body_A)
			
			OpenArr    = Body_A(n)
			EndArr     = Body_B(n)
			
			URLBodyStr = getHTTPPage(URL)
			
				IF Len(URLBodyStr) < 1 Then
				
				Response.Write("该页字节小于为0<br>")
				Call NextPage()'跳到下一页
		
				End IF
			
				URLBody    = Mid(URLBodyStr,LenOpen,len(URLBodyStr))
			
				IF Len(URLBody) < 1 Then
		
				Response.Write("该页已抓取完毕<br>")
				Call NextPage()'下一页
				
				End IF
			
			LenOpenArr = Newstring(URLBody,OpenArr)+Len(OpenArr)
			
			URLBody_1  = Mid(URLBody,LenOpenArr,len(URLBodyStr))
			
			LenEndStr  = Newstring(URLBody_1,EndArr)
			
			LenEndArr  = LenOpenArr + LenEndStr
			
			Body       = Mid(URLBody,LenOpenArr,LenEndArr-LenOpenArr-1)
			
			
					IF n       = 0 Then
					
						BodyList   = Body
					
					Else
					
						BodyList   = BodyList & Body_C & Body
					
					End IF
			
			Next
			
	LenOpen    = LenOpen + LenEndArr + len(EndArr)
	
	Next
	
IF Trim(BodyList) <> "" Then
				
				
					MailStr 	= False
					BodyListStr = ""
				IF Instr(BodyList,"@")= False or Instr(BodyList,".")= False or Len(BodyList)<8 Then
					BodyListStr = BodyListStr & "格式不正确|"
					MailStr = True
				End IF

					'============================================
					Set Rs = Conn_m.Execute("Select ID From Leach_Mail where Mail='"& BodyList &"'")
						IF Not(Rs.EOF and Rs.BOF) Then
						BodyListStr = BodyListStr & "此邮件地址已屏蔽|"
						MailStr = True
						End if 
						Rs.Close
					Set Rs = Nothing
							'================================================
							Comprise_MailStr = False
							Set Rs = Conn_m.Execute("Select Mail From Comprise_Mail")
								IF Not(Rs.EOF and Rs.BOF) Then
									While Not Rs.Eof
									IF InStr(Ucase(BodyList),""& Ucase(Trim(Rs("Mail"))) &"")>0 Then
									Comprise_MailStr = True
									End IF
									Rs.MoveNext
									Wend
										IF Comprise_MailStr = True Then
										BodyListStr = BodyListStr & "此邮件包含有屏蔽内容|"
										MailStr = True
										End iF
								End IF
								Rs.Close
							Set Rs = Nothing

			IF 	MailStr = False Then
				
						Conn_m.Execute("Update XMLHTTPURL Set URL_A_A = "& URL_A_A &" Where ID = "& ID &"")
						
							Set Rs = Conn_m.Execute("Select GroupID From Mail_Group Where TaskID = "& ID &"")
							
								IF Not(Rs.EOF AND Rs.bof) Then
								
									GroupID	= Rs("GroupID")
																	
								End IF
							
							Rs.Close
							
							Set Rs = Nothing
					
					Set Rs = Conn_m.Execute("Select Count(id) AS URLCount From Mail where Mail = '"& Trim(BodyList) &"'")
					
						IF Rs("URLCount") = 0 Then
						
						Conn_m.Execute("Insert Into Mail (Mail,GroupID,Ending) values ('"& BodyList &"',"& GroupID &",0)")
						
						BodyListStr	= "抓取到以下内容：<br>"& BodyList&"<br>"
						
						Else
						
						Response.Write("已有重复内容<br>")
						
						End IF
					
						Rs.Close
					
					Set Rs = Nothing
			
			End IF

IStr = IStr + 1

				IF IStr = T Then
				Response.Write("本页已抓到"& T &"条信息<br>")
				Call NextPage()'下一页
				End IF

End iF
	
				Response.Write("正在抓取"& URL &"<br>")
				Response.Write(BodyListStr)
				Response.Write("正进行到"& LenOpen &"...")
				Response.Write("<meta http-equiv=""refresh"" content="""& M &";url=XMLHTTPURL.asp?Makking=MakeTask&ID="& ID &"&URL_A_A="& URL_A_A &"&IStr="& IStr &"&LenOpen="& LenOpen &""">")
				Response.End()


Case ""
%>
            <table width="96%"  border="0" align="center" cellpadding="0" cellspacing="0">
              <tr> 
                <td align="center" bgcolor="ffffff"> <form method="post" name="form" action="XMLHTTPURL.asp?Makking=AddTask">
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr> 
                        <td width="19%" height="25" align="right">URL_A部分：</td>
                        <td width="81%" height="25"> <input name="URL_A" type="text" class="box6" id="URL_A2"> 
                        </td>
                      </tr>
                      <tr> 
                        <td height="25" align="right">URL参数初始值：</td>
                        <td height="25"><input name="URL_A_A" type="text" id="URL_A_A2"  onKeyPress	= "return regInput(this,	/^\d*\.?\d{0,2}$/,		String.fromCharCode(event.keyCode))" value="0"
		onpaste		= "return regInput(this,	/^\d*\.?\d{0,2}$/,		window.clipboardData.getData('Text'))"
		ondrop		= "return regInput(this,	/^\d*\.?\d{0,2}$/,		event.dataTransfer.getData('Text'))"></td>
                      </tr>
                      <tr> 
                        <td height="25" align="right">递增值：</td>
                        <td height="25"> <input name="URL_A_B" type="text" id="URL_A_B3" onKeyPress	= "return regInput(this,	/^\d*\.?\d{0,2}$/,		String.fromCharCode(event.keyCode))" value="1"
		onpaste		= "return regInput(this,	/^\d*\.?\d{0,2}$/,		window.clipboardData.getData('Text'))"
		ondrop		= "return regInput(this,	/^\d*\.?\d{0,2}$/,		event.dataTransfer.getData('Text'))"></td>
                      </tr>
                      <tr> 
                        <td height="25" align="right">结束值：</td>
                        <td height="25"> <input name="URL_A_C" type="text" id="URL_A_C2" onKeyPress	= "return regInput(this,	/^\d*\.?\d{0,2}$/,		String.fromCharCode(event.keyCode))" value="100"
		onpaste		= "return regInput(this,	/^\d*\.?\d{0,2}$/,		window.clipboardData.getData('Text'))"
		ondrop		= "return regInput(this,	/^\d*\.?\d{0,2}$/,		event.dataTransfer.getData('Text'))"></td>
                      </tr>
                      <tr> 
                        <td height="25" align="right">URL_B部分：</td>
                        <td height="25"><input name="URL_B" type="text" class="box6" id="URL_B2"></td>
                      </tr>
                      <tr> 
                        <td height="25" align="right">抓取内容前面参数：</td>
                        <td height="25"><input name="Body_A" type="text" class="box6" id="Body_A2" value="&lt;b&gt;"></td>
                      </tr>
                      <tr> 
                        <td height="25" align="right">抓取内容后面参数：</td>
                        <td height="25"> <input name="Body_B" type="text" class="box6" id="Body_B3" value="&lt;b&gt;"></td>
                      </tr>
                      <tr> 
                        <td height="25" align="right">间隔符：</td>
                        <td height="25"> <input name="Body_C" type="text" id="Body_B"></td>
                      </tr>
                      <tr> 
                        <td height="25" align="right">任务名称：</td>
                        <td height="25"><input name="TaskName" type="text" class="box6" id="TaskName2" value="抓取邮件"></td>
                      </tr>
                      <tr> 
                        <td height="25" align="right">抓取条数：</td>
                        <td height="25"><input name="T" type="text" id="T" onKeyPress	= "return regInput(this,	/^\d*\.?\d{0,2}$/,		String.fromCharCode(event.keyCode))" value="1"
		onpaste		= "return regInput(this,	/^\d*\.?\d{0,2}$/,		window.clipboardData.getData('Text'))"
		ondrop		= "return regInput(this,	/^\d*\.?\d{0,2}$/,		event.dataTransfer.getData('Text'))"></td>
                      </tr>
                      <tr> 
                        <td height="25" align="right">抓取频率：</td>
                        <td height="25"><input name="M" type="text" id="M2" onKeyPress	= "return regInput(this,	/^\d*\.?\d{0,2}$/,		String.fromCharCode(event.keyCode))" value="1"
		onpaste		= "return regInput(this,	/^\d*\.?\d{0,2}$/,		window.clipboardData.getData('Text'))"
		ondrop		= "return regInput(this,	/^\d*\.?\d{0,2}$/,		event.dataTransfer.getData('Text'))">
                          秒 </td>
                      </tr>
                    </table>
                    <p><br>
                      <input name="XML" type="image" src="Images/refer.gif" width="36" height="21" border="0" >
                      &nbsp;<a href="javascript:history.go(-1)"><img src="Images/back.gif" width="36" height="21" border="0"></a></p>
                  </form></td>
              </tr>
            </table>
<%
End Select
			Conn_m.Close
			Set Conn_m = Nothing
%>
          </td>
        </tr>
      </table></td>
  </tr>
</table>
<table width="98%"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="6"></td>
  </tr>
</table>
</body>
</html>

