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.dhdzp.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獲取遠(yuǎn)程網(wǎng)頁(yè)指定內(nèi)容開(kāi)始
Dim wstr,str,url,start,over,dtime
a="開(kāi)始內(nèi)容" 'ASP獲取目標(biāo)網(wǎng)頁(yè)內(nèi)容開(kā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)容開(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="http://www.dhdzp.com/"
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)文章
XMLHTTP利用POST發(fā)送表單時(shí)提交中文的問(wèn)題
XMLHTTP利用POST發(fā)送表單時(shí)提交中文的問(wèn)題...2006-06-06
ASP利用XMLHTTP實(shí)現(xiàn)表單提交以及cookies的發(fā)送的代碼
利用XMLHTTP來(lái)制作小偷的具體細(xì)節(jié)落伍很多人都發(fā)過(guò)和討論過(guò)了,但是在制作ASP小偷的過(guò)程中,很多人就發(fā)現(xiàn)ASP小偷不如PHP小偷的那么強(qiáng)大了。2008-08-08
一個(gè)帶采集遠(yuǎn)程文章內(nèi)容,保存圖片,生成文件等完整的采集功能
本文提供了一套完整的ASP采集功能函數(shù),包含提取地址的原字符,保存遠(yuǎn)程的文件到本地模擬登錄,獲取網(wǎng)頁(yè)源碼等功能函數(shù)2009-06-06
遠(yuǎn)程圖片自動(dòng)按文件夾上傳到服務(wù)器-默飛出品
遠(yuǎn)程圖片自動(dòng)按文件夾上傳到服務(wù)器-默飛出品...2006-06-06
ASP小偷(遠(yuǎn)程數(shù)據(jù)獲取)程序的入門教程
ASP小偷(遠(yuǎn)程數(shù)據(jù)獲取)程序的入門教程...2006-06-06

