核心函數代碼如下:
<% '用ASP獲取遠程目標網頁指定內容,代碼由廣州網站建設//m.survivalescaperooms.com提供 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獲取遠程網頁指定內容開始 Dim wstr,str,url,start,over,dtime a="開始內容" 'ASP獲取目標網頁內容開始標記 b="結束內容" 'ASP獲取網頁內容結束標記 url="http://sc.VeVB.COm/" wstr=getHTTPPage(url) start=Newstring(wstr,a) over=Newstring(wstr,b) body=mid(wstr,start,over-start) response.write ""&body&"" '輸出獲取到的網頁內容 'ASP獲取遠程網頁指定內容結束 %> 上面的代碼可以獲取指定網頁的內容,如果是全部獲取就更簡單了
代碼如下:
'ASP獲取遠程網頁指定內容開始 Dim wstr,str,url,start,over,dtime url="http://sc.VeVB.COm/" wstr=getHTTPPage(url) body=wstr
如果想將代碼保存到本地
Dim wstr,str,url,start,over,dtimeurl="http://m.survivalescaperooms.com/"wstr=getHTTPPage(url)filename="index.htm"if wstr<>"" and request("action")="makeindex" thenbody=wstrSet fso = Server.CreateObject("Scripting.FileSystemObject")Set fout = fso.CreateTextFile(server.mappath(""&filename&""))fout.Write bodyfout.closeset fout=nothingset fso=nothingIf Err.number=0 thenresponse.write("<div class=""tishi"">首頁生成成功!!</div>")end ifend if具體的大家可以根據需要自行修改即可。
以上就是asp獲取遠程網頁的指定內容的實現代碼的詳細內容,更多關于獲取遠程網頁內容的資料請關注武林網其它相關文章!
新聞熱點
疑難解答