国产成人精品18p,天天干成人网,无码专区狠狠躁天天躁,美女脱精光隐私扒开免费观看

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

發(fā)布時(shí)間:2021-08-17 12:10 來(lái)源: 閱讀:0 作者: 欄目: ASP 歡迎投稿:712375056

Asp 使用 Microsoft.XMLHTTP 抓取網(wǎng)頁(yè)內容(沒(méi)用亂碼),并過(guò)濾需要的內容

示例源碼:
代碼如下:
<%
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 抓取主要內容
strBody = GetBody(strHTML,"<div id=""Div_newsContentc"" class=""cnt"">","</div>",0,0)
strBody =Replace(strBody,"(本文首發(fā)于","")
strBody =Replace(strBody,"財富動(dòng)力網(wǎng)</a>,轉載請注明出處。)","")
strBody =Replace(strBody,"本文首發(fā)于,轉載請注明出處。)","")
strBody =Replace(strBody,"財富動(dòng)力網(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"

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


REM 使用正則表達式,抓取之內標記的內容
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 過(guò)濾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
%>

效果圖如下: 
 

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。

WW欧日韩视频高清在线| 日本五月天婷久久网站| 亚洲欭美日韩颜射在线二| 国内外精品激情刺激在线| 国产特级毛片AAAAAAA高清| 怡红院A∨人人爰人人爽|