XMLHttp ASP遠(yuǎn)程獲取網(wǎng)頁(yè)內(nèi)容代碼
更新時(shí)間:2008年11月10日 00:23:30 作者:
asp下利用xmlhttp獲取網(wǎng)頁(yè)內(nèi)容的方法這個(gè)方法一般比較通用的,然后通過(guò)字符截取網(wǎng)頁(yè)的內(nèi)容。
復(fù)制代碼 代碼如下:
url="http://www.csdn.net/"
wstr=getHTTPPage(url)
start=Newstring(wstr,"資源精選<!-- 下載 -->")
over=Newstring(wstr,"<div class=""friendlink"">")
body=mid(wstr,200,500)
response.write body
Function getHTTPPage(url)
dim objXML
set objXML=createobject("MSXML2.XMLHTTP")'定義
objXML.open "GET",url,false'打開(kāi)
objXML.send()'發(fā)送
If objXML.readystate<>4 then '判斷文檔是否已經(jīng)解析完,以做客戶端接受返回消息
exit function
End If
getHTTPPage=bBytesToBstr(objXML.responseBody)'返回信息,同時(shí)用函數(shù)定義編碼
set objXML=nothing'關(guān)閉
if err.number<>0 then err.Clear
End Function
Function Newstring(wstr,strng)
Newstring=Instr(lcase(wstr),lcase(strng))
if Newstring<=0 then Newstring=Len(wstr)
End Function
Function bBytesToBstr(body)
dim objstream
set objstream = CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = "gb2312"
'轉(zhuǎn)換原來(lái)默認(rèn)的UTF-8編碼轉(zhuǎn)換成GB2312編碼,否則直接用XMLHTTP調(diào)用有中文字符的網(wǎng)頁(yè)得到的將是亂碼
bBytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
end Function
Function BytesToBstr(body)
dim objstream
set objstream = CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = "utf-8"
'轉(zhuǎn)換原來(lái)默認(rèn)的UTF-8編碼轉(zhuǎn)換成GB2312編碼,否則直接用XMLHTTP調(diào)用有中文字符的網(wǎng)頁(yè)得到的將是亂碼
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
end Function
相關(guān)文章
msxml3.dll 錯(cuò)誤 800c0005 解決方案
在運(yùn)用xmlhttp組件編寫(xiě)程序中,會(huì)碰到msxml3.dll 錯(cuò)誤 800c0005系統(tǒng)未找到指定的資源。這種錯(cuò)誤,網(wǎng)上對(duì)這種錯(cuò)誤的產(chǎn)生原因有很多鐘解釋,大體說(shuō)是因?yàn)榉阑饓騏DP站口權(quán)限造成了,也說(shuō)了相應(yīng)的解決辦法2006-08-08
asp下以Json獲取中國(guó)天氣網(wǎng)天氣的代碼
這兩天搞個(gè)天氣預(yù)報(bào),記得以前用.net版本有種是抓取百度天氣寫(xiě)入txt,再讀取。時(shí)間久了,txt很多。感覺(jué)不是很好。2010-07-07
使用xmlHttp結(jié)合ASP實(shí)現(xiàn)網(wǎng)頁(yè)的異步調(diào)用
使用xmlHttp結(jié)合ASP實(shí)現(xiàn)網(wǎng)頁(yè)的異步調(diào)用...2006-06-06
ASP小偷(遠(yuǎn)程數(shù)據(jù)獲取)程序入門(mén)教程
ASP小偷(遠(yuǎn)程數(shù)據(jù)獲取)程序入門(mén)教程...2006-06-06
網(wǎng)站生成靜態(tài)頁(yè)面攻略3:防采集策略
網(wǎng)站生成靜態(tài)頁(yè)面攻略3:防采集策略...2006-08-08

