最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
asp 利用 xmlhttp 抓取网页内容
时间:2022-06-30 09:28:25 编辑:袖梨 来源:一聚教程网
抓取网页。偶要实现实实更新天气预报。利用了XMLHTTP组件,抓取网页的指定部分。
需要分件html源代码
此例中的被抓取的html源代码如下
而程序中是从
以2004年8月24日为关键字搜索,直到结速
而抓取的内容就变成了"2004年8月24日星期二;白天:晴有时多云南风3―4级;夜间:晴南风3―4级;气温:最高29℃最低19℃ "
干干净净的了。记录一下。
<%
On Error Resume Next
Server.ScriptTimeOut=9999999
Function getHTTPPage(Path)
t = GetBody(Path)
getHTTPPage=BytesToBstr(t,"GB2312")
End function
Function GetBody(url)
on error resume next
Set Retrieval = CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", url, False, "", ""
.Send
GetBody = .ResponseBody
End With
Set Retrieval = Nothing
End Function
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
End Function
Function Newstring(wstr,strng)
Newstring=Instr(lcase(wstr),lcase(strng))
if Newstring<=0 then Newstring=Len(wstr)
End Function
%>
<%
Dim wstr,str,url,start,over,dtime
dtime=Year(Date)&"年"&Month(Date)&"月"&Day(Date)&"日"
需要分件html源代码
此例中的被抓取的html源代码如下
2004年8月24日星期二;白天:晴有时多云南风3―4级;夜间:晴南风3―4级;气温:最高29℃最低19℃
而程序中是从
以2004年8月24日为关键字搜索,直到结速
而抓取的内容就变成了"2004年8月24日星期二;白天:晴有时多云南风3―4级;夜间:晴南风3―4级;气温:最高29℃最低19℃ "
干干净净的了。记录一下。
<%
On Error Resume Next
Server.ScriptTimeOut=9999999
Function getHTTPPage(Path)
t = GetBody(Path)
getHTTPPage=BytesToBstr(t,"GB2312")
End function
Function GetBody(url)
on error resume next
Set Retrieval = CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", url, False, "", ""
.Send
GetBody = .ResponseBody
End With
Set Retrieval = Nothing
End Function
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
End Function
Function Newstring(wstr,strng)
Newstring=Instr(lcase(wstr),lcase(strng))
if Newstring<=0 then Newstring=Len(wstr)
End Function
%>
<%
Dim wstr,str,url,start,over,dtime
dtime=Year(Date)&"年"&Month(Date)&"月"&Day(Date)&"日"
相关文章
- 《晶核》团本奖励领取如何 06-16
- 热门2025币圈十大全球交易所加密货币排行-最省钱现货交易平台币安推荐 06-16
- 《艾塔纪元》武器升级怎么样 06-16
- DYθR 创始人深度剖析:解密代币价格涨跌背后的群体行为密码 06-16
- 最新正规全球交易所2025数字资产交易榜单-最安全虚拟币交易app币安推荐 06-16
- 《空之要塞:启航》完美链接第四十一关怎么通关最快 06-16