当前位置: 移动技术网 > IT编程>开发语言>Asp > asp中利用xmlhttp抓取网页内容的代码

asp中利用xmlhttp抓取网页内容的代码

2017年12月08日  | 移动技术网IT编程  | 我要评论
需要分件html源代码
此例中的被抓取的html源代码如下
<p align=left>2004年8月24日星期二;白天:晴有时多云南风3—4级;夜间:晴南风3—4级;气温:最高29℃最低19℃ </p>
而程序中是从
以2004年8月24日为关键字搜索,直到</p>结速
而抓取的内容就变成了"2004年8月24日星期二;白天:晴有时多云南风3—4级;夜间:晴南风3—4级;气温:最高29℃最低19℃ "
干干净净的了。记录一下。

复制代码 代码如下:

<%
on error resume next
server.scripttimeout=9999999
function gethttppage(path)
t = getbody(path)
gethttppage=bytestobstr(t,"gb2312")
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
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 newstring(wstr,strng)
newstring=instr(lcase(wstr),lcase(strng))
if newstring<=0 then newstring=len(wstr)
end function
%>
<html>
<body bgcolor=#ffffff leftmargin=0 topmargin=0 marginheight=0 marginwidth=0>
<!-- 开始 -->
<%
dim wstr,str,url,start,over,dtime
dtime=year(date)&"年"&month(date)&"月"&day(date)&"日"
url="//www.jb51.net/"
wstr=gethttppage(url)
start=newstring(wstr,dtime)
over=newstring(wstr,"</p>")
body=mid(wstr,start,over-start)
response.write "<marquee onmouseover=this.stop(); onmouseout=this.start();>"&body&"</marquee>"

%>
<!-- 结束 -->
</body></html>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网