asp中利用xmlhttp抓取網頁內容的代碼
2024-05-04 10:59:44
供稿:網友
需要分件html源代碼
此例中的被抓取的html源代碼如下
<p align=left>2004年8月24日星期二;白天:晴有時多云南風3—4級;夜間:晴南風3—4級;氣溫:最高29℃最低19℃ </p>
而程序中是從
以2004年8月24日為關鍵字搜索,直到</p>結速
而抓取的內容就變成了"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
%>
<html>
<BODY bgColor=#ffffff leftMargin=0 topMargin=0 MARGINHEIGHT=0 MARGINWIDTH=0>
<!-- 開始 -->
<%
Dim wstr,str,url,start,over,dtime
dtime=Year(Date)&"年"&Month(Date)&"月"&Day(Date)&"日"
url="http://www.49028c.com/"
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>"
%>
<!-- 結束 -->
</body></html>
您可能感興趣的文章:
用asp+xmlhttp編寫web采集程序asp.net HttpWebRequest自動識別網頁編碼Asp.net XMLHTTP封裝類(GET,Post發送和接收數據)運行asp.net時出現 http錯誤404-文件或目錄未找到Javascript+XMLHttpRequest+asp.net無刷新讀取數據庫數據asp.net利用HttpModule實現防sql注入asp.net 模擬提交有文件上傳的表單(通過http模擬上傳文件)asp頁面提示Response 對象 錯誤 ASP 0156 : 80004005 HTTP 頭錯誤Asp WinHttp.WinHttpRequest.5.1 對象使用詳解 偽造 HTTP 頭信息Asp 使用 Microsoft.XMLHTTP 抓取網頁內容并過濾需要的asp中使用MSXML2.ServerXMLHTTP實現異步請求例子解決ASP中http狀態跳轉返回錯誤頁的問題