最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Asp 使用 Microsoft.XMLHTTP 抓取網(wǎng)頁內(nèi)容并過濾需要的

 更新時間:2014年05月14日 09:08:51   作者:  
這篇文章主要介紹了Asp 使用 Microsoft.XMLHTTP 抓取網(wǎng)頁內(nèi)容(沒用亂碼),并過濾需要的內(nèi)容
Asp 使用 Microsoft.XMLHTTP 抓取網(wǎng)頁內(nèi)容(沒用亂碼),并過濾需要的內(nèi)容

示例源碼:
復制代碼 代碼如下:

<%
Dim xmlUrl,http,strHTML,strBody
xmlUrl = Request.QueryString("u")

REM 異步讀取XML源
Set http = server.CreateObject("Microsoft.XMLHTTP")
http.Open "POST",xmlUrl,false
http.setrequestheader "User-Agent", "Mozilla/4.0"
http.setrequestheader "Connection", "Keep-Alive"
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.Send()

strHTML = BytesToBstr(http.ResponseBody)
set http = nothing

REM 抓取主要內(nèi)容
strBody = GetBody(strHTML,"<div id=""Div_newsContentc"" class=""cnt"">","</div>",0,0)
strBody =Replace(strBody,"(本文首發(fā)于","")
strBody =Replace(strBody,"財富動力網(wǎng)</a>,轉(zhuǎn)載請注明出處。)","")
strBody =Replace(strBody,"本文首發(fā)于,轉(zhuǎn)載請注明出處。)","")
strBody =Replace(strBody,"財富動力網(wǎng)</a>:http://www.927953.com","")
strBody =Replace(strBody,"本文首發(fā)于","")

Response.Write RegRemoveHref(strBody)

REM 獲取對應網(wǎng)址響應的HTML
Function BytesToBstr(body)
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 = "UTF-8"

'轉(zhuǎn)換原來默認的UTF-8編碼轉(zhuǎn)換成GB2312編碼,否則直接用
'XMLHTTP調(diào)用有中文字符的網(wǎng)頁得到的將是亂碼
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function


REM 使用正則表達式,抓取之內(nèi)標記的內(nèi)容
Function GetBody(ConStr,StartStr,OverStr,IncluL,IncluR)
If ConStr="$False$" or ConStr="" or IsNull(ConStr)=True Or StartStr="" or IsNull(StartStr)=True Or OverStr="" or IsNull(OverStr)=True Then
GetBody="$False$"
Exit Function
End If
Dim ConStrTemp
Dim Start,Over
ConStrTemp=Lcase(ConStr)
StartStr=Lcase(StartStr)
OverStr=Lcase(OverStr)
Start = InStrB(1, ConStrTemp, StartStr, vbBinaryCompare)
If Start<=0 then
GetBody="$False$"
Exit Function
Else
If IncluL=False Then
Start=Start+LenB(StartStr)
End If
End If
Over=InStrB(Start,ConStrTemp,OverStr,vbBinaryCompare)
If Over<=0 Or Over<=Start then
GetBody="$False$"
Exit Function
Else
If IncluR=True Then
Over=Over+LenB(OverStr)
End If
End If
GetBody=MidB(ConStr,Start,Over-Start)
End Function

REM 過濾a超鏈接
Function RegRemoveHref(HTMLstr)
Set ra = New RegExp
ra.IgnoreCase = True
ra.Global = True
ra.Pattern = "<a[^>]+>(.+?)<\/a>"

RegRemoveHref = Replace(ra.replace(HTMLstr,"$1"),"href=""http://www.927953.com""","")
END Function
%>

效果圖如下: 
 

相關文章

最新評論

石林| 原平市| 洱源县| 连云港市| 湖北省| 阿拉尔市| 游戏| 甘泉县| 庆城县| 忻城县| 庄河市| 香港| 南充市| 犍为县| 东乡县| 宣武区| 和硕县| 台江县| 长汀县| 西藏| 通山县| 治县。| 故城县| 灵山县| 平泉县| 常宁市| 环江| 孟州市| 若羌县| 高唐县| 杭锦后旗| 百色市| 额敏县| 武陟县| 江油市| 新乐市| 潜山县| 湖南省| 贵德县| 南丰县| 台山市|