- 資訊首頁(yè) > 開(kāi)發(fā)技術(shù) > web開(kāi)發(fā) > ASP >
- asp獲取遠程網(wǎng)頁(yè)的指定內容的實(shí)現代碼
核心函數代碼如下:
<% '用ASP獲取遠程目標網(wǎng)頁(yè)指定內容,代碼由廣州網(wǎng)站建設//www.jb51.net提供 On Error Resume Next Server.ScriptTimeOut=9999999 Function getHTTPPage(Path) t = GetBody(Path) getHTTPPage=BytesToBstr(t,"GB2312") End function Function Newstring(wstr,strng) Newstring=Instr(lcase(wstr),lcase(strng)) if Newstring<=0 then Newstring=Len(wstr) 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 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 'ASP獲取遠程網(wǎng)頁(yè)指定內容開(kāi)始 Dim wstr,str,url,start,over,dtime a="開(kāi)始內容" 'ASP獲取目標網(wǎng)頁(yè)內容開(kāi)始標記 b="結束內容" 'ASP獲取網(wǎng)頁(yè)內容結束標記 url="http://sc.jb51.net/" wstr=getHTTPPage(url) start=Newstring(wstr,a) over=Newstring(wstr,b) body=mid(wstr,start,over-start) response.write ""&body&"" '輸出獲取到的網(wǎng)頁(yè)內容 'ASP獲取遠程網(wǎng)頁(yè)指定內容結束 %>
上面的代碼可以獲取指定網(wǎng)頁(yè)的內容,如果是全部獲取就更簡(jiǎn)單了
代碼如下:
'ASP獲取遠程網(wǎng)頁(yè)指定內容開(kāi)始 Dim wstr,str,url,start,over,dtime url="http://sc.jb51.net/" wstr=getHTTPPage(url) body=wstr
如果想將代碼保存到本地
Dim wstr,str,url,start,over,dtime url="https://www.jb51.net/" wstr=getHTTPPage(url) filename="index.htm" if wstr<>"" and request("action")="makeindex" then body=wstr Set fso = Server.CreateObject("Scripting.FileSystemObject") Set fout = fso.CreateTextFile(server.mappath(""&filename&"")) fout.Write body fout.close set fout=nothing set fso=nothing If Err.number=0 then response.write("<div class=""tishi"">首頁(yè)生成成功??!</div>") end if end if
具體的大家可以根據需要自行修改即可。
以上就是asp獲取遠程網(wǎng)頁(yè)的指定內容的實(shí)現代碼的詳細內容,更多關(guān)于獲取遠程網(wǎng)頁(yè)內容的資料請關(guān)注腳本之家其它相關(guān)文章!
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。
Copyright ? 2009-2022 56dr.com. All Rights Reserved. 特網(wǎng)科技 特網(wǎng)云 版權所有 特網(wǎng)科技 粵ICP備16109289號
域名注冊服務(wù)機構:阿里云計算有限公司(萬(wàn)網(wǎng)) 域名服務(wù)機構:煙臺帝思普網(wǎng)絡(luò )科技有限公司(DNSPod) CDN服務(wù):阿里云計算有限公司 百度云 中國互聯(lián)網(wǎng)舉報中心 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證B2
建議您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流瀏覽器瀏覽本網(wǎng)站