XMLHTTP批量抓取遠程資料

來源:互聯網
上載者:User

可以在此基礎上結合Regex做成更好的效果,希望大家能分享一下Xmlhttp的session共用技術

<html>
<head>
<title>AUTOGET</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#FFFFFF" style="font-family:Arial;font-size:12px">
<%
'=================================================
'FileName: Getit.Asp
'Intro : Auto Get Data From Remote WebSite
'Author: Babyt(阿泰)
'URL: http://blog.csdn.net/babyt
'createAt: 2002-02 Lastupdate:2004-09
'DB Table : data
'Table Field:
' UID -> Long -> Keep ID Of the pages
' UContent -> Text -> Keep Content Of the Pages(HTML)
'=================================================

Server.ScriptTimeout=5000

'on error resume next
Set conn = Server.createObject("ADODB.Connection")
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("getit.mdb")
Set rs = Server.createObject("ADODB.Recordset")
sql="select * from data"
rs.open sql,conn,1,3

Dim comeFrom,myErr,myCount

'========================================================
comeFrom="http://www.xxx.com/U.asp?ID="
myErr1="該資料不存在"
myErr2="該資料已隱藏"
'========================================================

'***************************************************************
' 只需要更改這裡 i 的始點intMin和終點intMax,設定步長intStep
' 每次區間設定成5萬左右。估計要兩個多小時。期間不需要人工幹預
'****************************************************************
intMin=0
intMax=10000
'設定步長
intStep=100

'==========================================================
'以下代碼不要更改
'==========================================================
Call GetPart (intMin)
Response.write "已經轉換完成" & intMin & "~~" & intMax & "之間的資料"
rs.close
Set rs=Nothing
conn.Close
set conn=nothing
%>
</body>
</html>
<%
'使用XMLHTTP抓取地址並進次內容處理
Function GetBody(Url)
Dim objXML
On Error Resume Next
Set objXML = createObject("Microsoft.XMLHTTP")
With objXML
.Open "Get", Url, False, "", ""
.Send
GetBody = .ResponseBody
End With
GetBody=BytesToBstr(GetBody,"GB2312")
Set objXML = Nothing
End Function
'使用Adodb.Stream處理位元據
Function BytesToBstr(strBody,CodeBase)
dim objStream
set objStream = Server.createObject("Adodb.Stream")
objStream.Type = 1
objStream.Mode =3
objStream.Open
objStream.Write strBody
objStream.Position = 0
objStream.Type = 2
objStream.Charset = CodeBase
BytesToBstr = objStream.ReadText
objStream.Close
set objStream = nothing
End Function
'主函數
Function GetPart(iStart)
Dim iGo
time1=timer()
myCount=0
For iGo=iStart To iStart+intStep
If iGo<=intMax Then
Response.Execute comeFrom & iGo
'進行簡單的資料處理
content = GetBody(comeFrom & iGo )
content = Replace(content,chr(34),""")
If instr(content,myErr1) OR instr(content,myErr2) Then
'跳過錯誤資訊
Else
'寫入資料庫
rs.AddNew
rs("UID")=iGo
'********************************
rs("UContent")=Replace(content,""",chr(34))
'*********************************
rs.update
myCount=myCount+1
Response.Write iGo & "<BR>"
Response.Flush
End If
Else
Response.write "<font color=red>成功抓取"&myCount&"條記錄,"
time2=timer()
Response.write "耗時:" & Int(FormatNumber((time2-time1)*1000000,3)) & " 秒</font><BR>"
Response.Flush
Exit Function
End If
Next
Response.write "<font color=red>成功抓取"&myCount&"條記錄,"
time2=timer()
Response.write "耗時:" & CInt(FormatNumber((time2-time1),3)) & " 秒</font><BR>"
Response.Flush
'遞迴
GetPart(iGo+1)
End Function%>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.