asp获取远程网页的指定内容的实现代码
程序员文章站
2022-05-18 11:37:09
代码如下: 复制代码 代码如下: <% '用asp获取远程目标网页指定内容,代码由广州网站建设//www.jb51.net提供 on error resume nex...
代码如下:
<%
'用asp获取远程目标网页指定内容,代码由广州网站建设//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
复制代码 代码如下:
<%
'用asp获取远程目标网页指定内容,代码由广州网站建设//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