XMLHTTP抓取遠(yuǎn)程數(shù)據(jù)的后期處理
更新時(shí)間:2006年09月04日 00:00:00 作者:
<%
hehe = Hello("http://mmsg.qq.com/cgi-bin/gddylist?Type=13&Sort=1&Page=3", "<html>", "</html>", ".*(<td width=""35%"" bgcolor=""#[\dABCDE]{6}"">(.*)</td>)[.\n]*", "<font style=""font-size:9pt;"" color=blue>$2</font><br>")
response.Write hehe
Function Hello(strUrl, strStart, strEnd, patrn, replStr)
Str = GetBody(strUrl)
Str = MyMid(Str, strStart, strEnd)
Str = ReplaceTest(patrn, replStr, Str)
Hello = Str
End Function
Function MyMid(Str, strstart, strend)
If strstart = "" Then
i = 0
Else
i = InStr(Str, strstart)
End If
If strend = "" Then
j = Len(Str)
Else
j = InStr(i, Str, strend)
End If
MyMid = Mid(Str, i, j - i + 1)
End Function
Function ReplaceTest(patrn, replStr, str1)
Dim regEx, match, matches
Set regEx = New RegExp
regEx.Pattern = patrn
regEx.IgnoreCase = True
regEx.Global = True
Set matches = regEx.Execute(str1)
For Each match in matches
ReplaceTest = ReplaceTest®Ex.Replace(Match.Value, replStr)
Next
End Function
Function GetBody(Url)
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
Function BytesToBstr(strBody, CodeBase)
Set objStream = Server.createObject("Adodb.Stream")
With objStream
.Type = 1
.Mode = 3
.Open
.Write strBody
.Position = 0
.Type = 2
.Charset = CodeBase
BytesToBstr = .ReadText
.Close
End With
Set objStream = Nothing
End Function
%>
其他調(diào)用示例:
hehe = Hello("http://list.mp3.baidu.com/song/A.htm", "<table width=""90%"" border=""0"" align=""center"" cellpadding=""3"" cellspacing=""0"" bgcolor=""#f5f5f5"" >", "<DIV align=center>", ".*(<td width=""20%""><a href="".*\.htm"" target=_blank>)(.*)(</a></td>)[.\n]*", "<font style=""font-size:9pt;"" color=blue>$2</font><br>")
hehe = Hello("http://mmsg.qq.com/cgi-bin/gddylist?Type=13&Sort=1&Page=3", "<html>", "</html>", ".*(<td width=""35%"" bgcolor=""#[\dABCDE]{6}"">(.*)</td>)[.\n]*", "<font style=""font-size:9pt;"" color=blue>$2</font><br>")
response.Write hehe
Function Hello(strUrl, strStart, strEnd, patrn, replStr)
Str = GetBody(strUrl)
Str = MyMid(Str, strStart, strEnd)
Str = ReplaceTest(patrn, replStr, Str)
Hello = Str
End Function
Function MyMid(Str, strstart, strend)
If strstart = "" Then
i = 0
Else
i = InStr(Str, strstart)
End If
If strend = "" Then
j = Len(Str)
Else
j = InStr(i, Str, strend)
End If
MyMid = Mid(Str, i, j - i + 1)
End Function
Function ReplaceTest(patrn, replStr, str1)
Dim regEx, match, matches
Set regEx = New RegExp
regEx.Pattern = patrn
regEx.IgnoreCase = True
regEx.Global = True
Set matches = regEx.Execute(str1)
For Each match in matches
ReplaceTest = ReplaceTest®Ex.Replace(Match.Value, replStr)
Next
End Function
Function GetBody(Url)
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
Function BytesToBstr(strBody, CodeBase)
Set objStream = Server.createObject("Adodb.Stream")
With objStream
.Type = 1
.Mode = 3
.Open
.Write strBody
.Position = 0
.Type = 2
.Charset = CodeBase
BytesToBstr = .ReadText
.Close
End With
Set objStream = Nothing
End Function
%>
其他調(diào)用示例:
hehe = Hello("http://list.mp3.baidu.com/song/A.htm", "<table width=""90%"" border=""0"" align=""center"" cellpadding=""3"" cellspacing=""0"" bgcolor=""#f5f5f5"" >", "<DIV align=center>", ".*(<td width=""20%""><a href="".*\.htm"" target=_blank>)(.*)(</a></td>)[.\n]*", "<font style=""font-size:9pt;"" color=blue>$2</font><br>")
相關(guān)文章
遠(yuǎn)程圖片自動(dòng)按文件夾上傳到服務(wù)器-默飛出品
遠(yuǎn)程圖片自動(dòng)按文件夾上傳到服務(wù)器-默飛出品...2006-06-06
ASP 程序?qū)崿F(xiàn)自動(dòng)升級(jí)功能
ASP 程序?qū)崿F(xiàn)自動(dòng)升級(jí)功能...2007-02-02
利用xmlhttp和adodb.stream加緩存技術(shù)下載遠(yuǎn)程Web文件
利用xmlhttp和adodb.stream加緩存技術(shù)下載遠(yuǎn)程Web文件...2006-06-06
使用asp下的adodb.stream 下載文件而不是打開(kāi)
在瀏覽器的地址欄里直接輸入一個(gè)doc或xls或jpg的文件的url路徑,那么該文件會(huì)直接顯示在瀏覽器里。而在很多時(shí)候我們希望能直接彈出下載提示框讓用戶(hù)下載,我們?cè)撛趺崔k呢2007-12-12
非常不錯(cuò)的flash采集程序測(cè)試通過(guò)
非常不錯(cuò)的flash采集程序測(cè)試通過(guò)...2006-12-12
XMLHttp ASP遠(yuǎn)程獲取網(wǎng)頁(yè)內(nèi)容代碼
asp下利用xmlhttp獲取網(wǎng)頁(yè)內(nèi)容的方法這個(gè)方法一般比較通用的,然后通過(guò)字符截取網(wǎng)頁(yè)的內(nèi)容。2008-11-11

