国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > ASP > 正文

XMLHttp ASP遠程獲取網頁內容代碼

2024-05-04 11:09:08
字體:
來源:轉載
供稿:網友
asp下利用xmlhttp獲取網頁內容的方法這個方法一般比較通用的,然后通過字符截取網頁的內容。
 
 
 

 

復制代碼代碼如下:

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'打開 
objXML.send()'發送 
If objXML.readystate<>4 then '判斷文檔是否已經解析完,以做客戶端接受返回消息 
exit function 
End If 
getHTTPPage=bBytesToBstr(objXML.responseBody)'返回信息,同時用函數定義編碼 
set objXML=nothing'關閉 
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" 
'轉換原來默認的UTF-8編碼轉換成GB2312編碼,否則直接用XMLHTTP調用有中文字符的網頁得到的將是亂碼 
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" 
'轉換原來默認的UTF-8編碼轉換成GB2312編碼,否則直接用XMLHTTP調用有中文字符的網頁得到的將是亂碼 
BytesToBstr = objstream.ReadText 
objstream.Close 
set objstream = nothing 
end Function

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 景洪市| 卓资县| 沧州市| 将乐县| 宝兴县| 崇仁县| 读书| 延安市| 桑植县| 正镶白旗| 清涧县| 左云县| 朝阳市| 鱼台县| 天祝| 丹凤县| 池州市| 汉中市| 鄢陵县| 乐清市| 石家庄市| 隆林| 永宁县| 赣州市| 宜兰县| 新建县| 嘉黎县| 新民市| 余江县| 托克托县| 肇东市| 临泉县| 望都县| 义马市| 通州区| 灵山县| 隆林| 伊宁市| 射洪县| 永济市| 和田市|