采集原理:
采集程序的主要步驟如下:
一、獲取被采集的頁面的內容
二、從獲取代碼中提取所有用的數據
一、獲取被采集的頁面的內容
我目前所掌握的ASP常用獲取被采集的頁面的內容方法:
1、用serverXMLHTTP組件獲取數據
Function GetBody(weburl)
'-----------------翟振愷(小琦)
'創建對象
Dim ObjXMLHTTP
Set ObjXMLHTTP=Server.CreateObject("MSXML2.serverXMLHTTP")
'請求文件,以異步形式
ObjXMLHTTP.Open "GET",weburl,False
ObjXMLHTTP.send
While ObjXMLHTTP.readyState <> 4
ObjXMLHTTP.waitForResponse 1000
Wend
'得到結果
GetBody=ObjXMLHTTP.responseBody
'釋放對象
Set ObjXMLHTTP=Nothing
'-----------------翟振愷(小琦)
End Function
調用方法:GetBody(文件的URLf地址)
2、或XMLHTTP組件獲取數據
Function GetBody(weburl)
'-----------------翟振愷(小琦)
'創建對象
Set Retrieval = CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", weburl, False, "", ""
.Send
GetBody = .ResponseBody
End With
'釋放對象
Set Retrieval = Nothing
'-----------------翟振愷(小琦)
End Function
調用方法:GetBody(文件的URLf地址)
這樣獲取的數據內容還需要進行編碼轉換才可以使用
Function BytesToBstr(body,Cset)
'-----------------翟振愷(小琦)
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
'-----------------翟振愷(小琦)
新聞熱點
疑難解答