抓取网页。偶要实现实实更新天气预报。利用了XMLHTTP组件,抓取网页的指定部分。
需要分件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℃ "
干干净净的了。记录一下。
<%
OnErrorResumeNext
Server.ScriptTimeOut=9999999
FunctiongetHTTPPage(Path)
t=GetBody(Path)
getHTTPPage=BytesToBstr(t,"GB2312")
Endfunction
FunctionGetBody(url)
onerrorresumenext
SetRetrieval=CreateObject("Microsoft.XMLHTTP")
WithRetrieval
.Open"Get",url,False,"",""
.Send
GetBody=.ResponseBody
EndWith
SetRetrieval=Nothing
EndFunction
FunctionBytesToBstr(body,Cset)
dimobjstream
setobjstream=Server.CreateObject("adodb.stream")
objstream.Type=1
objstream.Mode=3
objstream.Open
objstream.Writebody
objstream.Position=0
objstream.Type=2
objstream.Charset=Cset
BytesToBstr=objstream.ReadText
objstream.Close
setobjstream=nothing
EndFunction
FunctionNewstring(wstr,strng)
Newstring=Instr(lcase(wstr),lcase(strng))
ifNewstring<=0thenNewstring=Len(wstr)
EndFunction
%>
<html>
<BODYbgColor=#ffffffleftMargin=0topMargin=0MARGINHEIGHT=0MARGINWIDTH=0>
<!--开始-->
<%
Dimwstr,str,url,start,over,dtime
dtime=Year(Date)&"年"&Month(Date)&"月"&Day(Date)&"日"
url="http://www.qianhuaweb.com/"
wstr=getHTTPPage(url)
start=Newstring(wstr,dtime)
over=Newstring(wstr,"</p>")
body=mid(wstr,start,over-start)
response.write"<MARQUEEonmouseover=this.stop();onmouseout=this.start();>"&body&"</marquee>"
%>
<!--结束-->
</body></html>
优质内容筛选与推荐>>
1、常用的匹配正则表达式和实例2、oracle01--单表查询3、创建maven项目多模块项目4、Python 命名规范5、mysql触发器(Trigger)简明总结和使用实例