asp中利用xmlhttp抓取網(wǎng)頁(yè)內(nèi)容的代碼
更新時(shí)間:2012年10月16日 20:21:22 作者:
抓取網(wǎng)頁(yè)。偶要實(shí)現(xiàn)實(shí)實(shí)更新天氣預(yù)報(bào)。利用了XMLHTTP組件,抓取網(wǎng)頁(yè)的指定部分,其實(shí)很多的小偷程序要更好用
需要分件html源代碼
此例中的被抓取的html源代碼如下
<p align=left>2004年8月24日星期二;白天:晴有時(shí)多云南風(fēng)3—4級(jí);夜間:晴南風(fēng)3—4級(jí);氣溫:最高29℃最低19℃ </p>
而程序中是從
以2004年8月24日為關(guān)鍵字搜索,直到</p>結(jié)速
而抓取的內(nèi)容就變成了"2004年8月24日星期二;白天:晴有時(shí)多云南風(fēng)3—4級(jí);夜間:晴南風(fēng)3—4級(jí);氣溫:最高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
%>
<html>
<BODY bgColor=#ffffff leftMargin=0 topMargin=0 MARGINHEIGHT=0 MARGINWIDTH=0>
<!-- 開(kāi)始 -->
<%
Dim wstr,str,url,start,over,dtime
dtime=Year(Date)&"年"&Month(Date)&"月"&Day(Date)&"日"
url="http://chabaoo.cn/"
wstr=getHTTPPage(url)
start=Newstring(wstr,dtime)
over=Newstring(wstr,"</p>")
body=mid(wstr,start,over-start)
response.write "<MARQUEE onmouseover=this.stop(); onmouseout=this.start();>"&body&"</marquee>"
%>
<!-- 結(jié)束 -->
</body></html>
此例中的被抓取的html源代碼如下
<p align=left>2004年8月24日星期二;白天:晴有時(shí)多云南風(fēng)3—4級(jí);夜間:晴南風(fēng)3—4級(jí);氣溫:最高29℃最低19℃ </p>
而程序中是從
以2004年8月24日為關(guān)鍵字搜索,直到</p>結(jié)速
而抓取的內(nèi)容就變成了"2004年8月24日星期二;白天:晴有時(shí)多云南風(fēng)3—4級(jí);夜間:晴南風(fēng)3—4級(jí);氣溫:最高29℃最低19℃ "
干干凈凈的了。記錄一下。
復(fù)制代碼 代碼如下:
<%
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
%>
<html>
<BODY bgColor=#ffffff leftMargin=0 topMargin=0 MARGINHEIGHT=0 MARGINWIDTH=0>
<!-- 開(kāi)始 -->
<%
Dim wstr,str,url,start,over,dtime
dtime=Year(Date)&"年"&Month(Date)&"月"&Day(Date)&"日"
url="http://chabaoo.cn/"
wstr=getHTTPPage(url)
start=Newstring(wstr,dtime)
over=Newstring(wstr,"</p>")
body=mid(wstr,start,over-start)
response.write "<MARQUEE onmouseover=this.stop(); onmouseout=this.start();>"&body&"</marquee>"
%>
<!-- 結(jié)束 -->
</body></html>
您可能感興趣的文章:
- 用asp+xmlhttp編寫(xiě)web采集程序
- asp.net HttpWebRequest自動(dòng)識(shí)別網(wǎng)頁(yè)編碼
- Asp.net XMLHTTP封裝類(GET,Post發(fā)送和接收數(shù)據(jù))
- 運(yùn)行asp.net時(shí)出現(xiàn) http錯(cuò)誤404-文件或目錄未找到
- Javascript+XMLHttpRequest+asp.net無(wú)刷新讀取數(shù)據(jù)庫(kù)數(shù)據(jù)
- asp.net利用HttpModule實(shí)現(xiàn)防sql注入
- asp.net 模擬提交有文件上傳的表單(通過(guò)http模擬上傳文件)
- asp頁(yè)面提示Response 對(duì)象 錯(cuò)誤 ASP 0156 : 80004005 HTTP 頭錯(cuò)誤
- Asp WinHttp.WinHttpRequest.5.1 對(duì)象使用詳解 偽造 HTTP 頭信息
- Asp 使用 Microsoft.XMLHTTP 抓取網(wǎng)頁(yè)內(nèi)容并過(guò)濾需要的
- asp中使用MSXML2.ServerXMLHTTP實(shí)現(xiàn)異步請(qǐng)求例子
- 解決ASP中http狀態(tài)跳轉(zhuǎn)返回錯(cuò)誤頁(yè)的問(wèn)題
相關(guān)文章
asp下實(shí)現(xiàn)IP限制函數(shù)代碼
asp下實(shí)現(xiàn)IP限制函數(shù)代碼...2007-11-11asp中用insert into語(yǔ)句向數(shù)據(jù)庫(kù)插入記錄(添加信息)的方法
asp中用insert into語(yǔ)句向數(shù)據(jù)庫(kù)插入記錄信息的方法,學(xué)習(xí)的朋友可以參考下。2010-09-09用javascript解決外部數(shù)據(jù)抓取中的亂碼問(wèn)題
用javascript解決外部數(shù)據(jù)抓取中的亂碼問(wèn)題...2007-04-04在.NET Core 中使用 FluentValidation 進(jìn)行規(guī)則驗(yàn)證的方法
這篇文章主要介紹了在.NET Core 中使用 FluentValidation 進(jìn)行規(guī)則驗(yàn)證,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-02-02關(guān)于WPF?WriteableBitmap類直接操作像素點(diǎn)的問(wèn)題
WPF是微軟新一代圖形系統(tǒng),運(yùn)行在.NET Framework 3.0及以上版本下,為用戶界面、2D/3D 圖形、文檔和媒體提供了統(tǒng)一的描述和操作方法,本文重點(diǎn)給大家介紹WPF?WriteableBitmap類直接操作像素點(diǎn)的問(wèn)題,感興趣的朋友一起看看吧2022-01-01JScript中調(diào)用ActiveX獲取訪客網(wǎng)卡MAC地址實(shí)現(xiàn)代碼
這篇文章主要介紹了JScript中調(diào)用ActiveX獲取訪客網(wǎng)卡MAC地址實(shí)現(xiàn)代碼,注意本文代碼只適應(yīng)運(yùn)行在IE瀏覽器上,需要的朋友可以參考下2014-08-08