代碼如下:
複製代碼 代碼如下:<%
'用ASP擷取遠程目標網頁指定內容,代碼由廣州網站建設http://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擷取遠程網頁指定內容開始
Dim wstr,str,url,start,over,dtime
a="開始內容" 'ASP擷取目標網頁內容開始標記
b="結束內容" 'ASP擷取網頁內容結束標記
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&"" '輸出擷取到的網頁內容
'ASP擷取遠程網頁指定內容結束
%>
上面的代碼可以擷取指定網頁的內容,如果是全部擷取就更簡單了
核心代碼:複製代碼 代碼如下:'ASP擷取遠程網頁指定內容開始
Dim wstr,str,url,start,over,dtime
url="http://sc.jb51.net/"
wstr=getHTTPPage(url)
body=wstr