Asp 使用 Microsoft.XMLHTTP 抓取网页内容(没用乱码),并过滤需要的内容
示例源码:
复制代码 代码如下:
<%
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,"(本文首发于","")
strBody =Replace(strBody,"财富动力网</a>,转载请注明出处。)","")
strBody =Replace(strBody,"本文首发于,转载请注明出处。)","")
strBody =Replace(strBody,"财富动力网</a>:http://www.927953.com","")
strBody =Replace(strBody,"本文首发于","")
Response.Write RegRemoveHref(strBody)
REM 获取对应网址响应的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"
'转换原来默认的UTF-8编码转换成GB2312编码,否则直接用
'XMLHTTP调用有中文字符的网页得到的将是乱码
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 过滤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
%>
效果图如下:
示例源码:
复制代码 代码如下:
<%
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,"(本文首发于","")
strBody =Replace(strBody,"财富动力网</a>,转载请注明出处。)","")
strBody =Replace(strBody,"本文首发于,转载请注明出处。)","")
strBody =Replace(strBody,"财富动力网</a>:http://www.927953.com","")
strBody =Replace(strBody,"本文首发于","")
Response.Write RegRemoveHref(strBody)
REM 获取对应网址响应的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"
'转换原来默认的UTF-8编码转换成GB2312编码,否则直接用
'XMLHTTP调用有中文字符的网页得到的将是乱码
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 过滤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
%>
效果图如下:
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
暂无“Asp 使用 Microsoft.XMLHTTP 抓取网页内容并过滤需要的”评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新动态
2024年11月09日
2024年11月09日
- 雨林唱片《赏》新曲+精选集SACD版[ISO][2.3G]
- 罗大佑与OK男女合唱团.1995-再会吧!素兰【音乐工厂】【WAV+CUE】
- 草蜢.1993-宝贝对不起(国)【宝丽金】【WAV+CUE】
- 杨培安.2009-抒·情(EP)【擎天娱乐】【WAV+CUE】
- 周慧敏《EndlessDream》[WAV+CUE]
- 彭芳《纯色角3》2007[WAV+CUE]
- 江志丰2008-今生为你[豪记][WAV+CUE]
- 罗大佑1994《恋曲2000》音乐工厂[WAV+CUE][1G]
- 群星《一首歌一个故事》赵英俊某些作品重唱企划[FLAC分轨][1G]
- 群星《网易云英文歌曲播放量TOP100》[MP3][1G]
- 方大同.2024-梦想家TheDreamer【赋音乐】【FLAC分轨】
- 李慧珍.2007-爱死了【华谊兄弟】【WAV+CUE】
- 王大文.2019-国际太空站【环球】【FLAC分轨】
- 群星《2022超好听的十倍音质网络歌曲(163)》U盘音乐[WAV分轨][1.1G]
- 童丽《啼笑姻缘》头版限量编号24K金碟[低速原抓WAV+CUE][1.1G]