ASP获取远程网页的指定内容的函数


ASP #远程 #采集 #网页 #函数2012-05-11 09:29

先贴函数:

01<%
02'用ASP获取远程目标网页指定内容 更多的代码来这里找 http://yige.org
03On Error Resume Next
04Server.ScriptTimeOut=9999999
05Function getHTTPPage(Path)
06t = GetBody(Path)
07getHTTPPage=BytesToBstr(t,"GB2312")
08End function
09Function Newstring(wstr,strng)
10Newstring=Instr(lcase(wstr),lcase(strng))
11if Newstring<=0 then Newstring=Len(wstr)
12End Function
13Function BytesToBstr(body,Cset)
14dim objstream
15set objstream = Server.CreateObject("adodb.stream")
16objstream.Type = 1
17objstream.Mode =3
18objstream.Open
19objstream.Write body
20objstream.Position = 0
21objstream.Type = 2
22objstream.Charset = Cset
23BytesToBstr = objstream.ReadText
24objstream.Close
25set objstream = nothing
26End Function
27Function GetBody(url)
28on error resume next
29Set Retrieval = CreateObject("Microsoft.XMLHTTP")
30With Retrieval
31.Open "Get", url, False, "", ""
32.Send
33GetBody = .ResponseBody
34End With
35Set Retrieval = Nothing
36End Function
37%>
调用示例:

01'ASP获取远程网页指定内容开始
02Dim wstr,str,url,start,over,dtime
03a="开始内容" 'ASP获取目标网页内容开始标记
04b="结束内容" 'ASP获取网页内容结束标记
06wstr=getHTTPPage(url)
07start=Newstring(wstr,a)
08over=Newstring(wstr,b)
09body=mid(wstr,start,over-start)
10response.write ""&body;&"" '输出获取到的网页内容
11'ASP获取远程网页指定内容结束


相关文章

粤ICP备11097351号-1