asp獲取遠(yuǎn)程網(wǎng)頁(yè)的指定內(nèi)容的實(shí)現(xiàn)代碼
核心函數(shù)代碼如下:
<% '用ASP獲取遠(yuǎn)程目標(biāo)網(wǎng)頁(yè)指定內(nèi)容,代碼由廣州網(wǎng)站建設(shè)//www.dbjr.com.cn提供 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獲取遠(yuǎn)程網(wǎng)頁(yè)指定內(nèi)容開始 Dim wstr,str,url,start,over,dtime a="開始內(nèi)容" 'ASP獲取目標(biāo)網(wǎng)頁(yè)內(nèi)容開始標(biāo)記 b="結(jié)束內(nèi)容" 'ASP獲取網(wǎng)頁(yè)內(nèi)容結(jié)束標(biāo)記 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è)內(nèi)容 'ASP獲取遠(yuǎn)程網(wǎng)頁(yè)指定內(nèi)容結(jié)束 %>
上面的代碼可以獲取指定網(wǎng)頁(yè)的內(nèi)容,如果是全部獲取就更簡(jiǎn)單了
代碼如下:
'ASP獲取遠(yuǎn)程網(wǎng)頁(yè)指定內(nè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="http://www.dbjr.com.cn/" 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
具體的大家可以根據(jù)需要自行修改即可。
以上就是asp獲取遠(yuǎn)程網(wǎng)頁(yè)的指定內(nèi)容的實(shí)現(xiàn)代碼的詳細(xì)內(nèi)容,更多關(guān)于獲取遠(yuǎn)程網(wǎng)頁(yè)內(nèi)容的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
獨(dú)孤劍寫的馬克斯迅雷片庫(kù)采集插件1.4 官方最新版提供下載了
非常不錯(cuò)的采集迅雷插件,經(jīng)本人測(cè)試非常不錯(cuò),而且作者很熱心,是個(gè)好人,希望大家支持下,不要拿去賣了。2008-01-01實(shí)例講解實(shí)現(xiàn)抓取網(wǎng)上房產(chǎn)信息的ASP程序
實(shí)例講解實(shí)現(xiàn)抓取網(wǎng)上房產(chǎn)信息的ASP程序...2007-03-03提供幾個(gè)關(guān)于采集的函數(shù)(ASP)
提供幾個(gè)關(guān)于采集的函數(shù)(ASP)...2006-06-06利用MSXML2.XmlHttp和Adodb.Stream采集圖片
asp下經(jīng)常用來(lái)采集的兩個(gè)組件結(jié)合使用例子2008-05-05XMLHTTP利用POST發(fā)送表單時(shí)提交中文的問(wèn)題
XMLHTTP利用POST發(fā)送表單時(shí)提交中文的問(wèn)題...2006-06-06