转载自:www.csdn.net

抓取网页。偶要实现实实更新天气预报。利用了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℃ "
干干净净的了。记录一下。

[转载]XMLHTTP 抓取[天气预报]网页内容<%
[转载]XMLHTTP 抓取[天气预报]网页内容
On Error Resume Next
[转载]XMLHTTP 抓取[天气预报]网页内容Server.ScriptTimeOut
=9999999
[转载]XMLHTTP 抓取[天气预报]网页内容
Function getHTTPPage(Path)
[转载]XMLHTTP 抓取[天气预报]网页内容        t 
= GetBody(Path)
[转载]XMLHTTP 抓取[天气预报]网页内容        getHTTPPage
=BytesToBstr(t,"GB2312")
[转载]XMLHTTP 抓取[天气预报]网页内容
End function 
[转载]XMLHTTP 抓取[天气预报]网页内容
Function GetBody(url) 
[转载]XMLHTTP 抓取[天气预报]网页内容        
on error resume next
[转载]XMLHTTP 抓取[天气预报]网页内容        
Set Retrieval = CreateObject("Microsoft.XMLHTTP"
[转载]XMLHTTP 抓取[天气预报]网页内容        
With Retrieval 
[转载]XMLHTTP 抓取[天气预报]网页内容        .Open 
"Get", url, False"""" 
[转载]XMLHTTP 抓取[天气预报]网页内容        .Send 
[转载]XMLHTTP 抓取[天气预报]网页内容        GetBody 
= .ResponseBody
[转载]XMLHTTP 抓取[天气预报]网页内容        
End With 
[转载]XMLHTTP 抓取[天气预报]网页内容        
Set Retrieval = Nothing 
[转载]XMLHTTP 抓取[天气预报]网页内容
End Function
[转载]XMLHTTP 抓取[天气预报]网页内容
[转载]XMLHTTP 抓取[天气预报]网页内容
Function BytesToBstr(body,Cset)
[转载]XMLHTTP 抓取[天气预报]网页内容        
dim objstream
[转载]XMLHTTP 抓取[天气预报]网页内容        
set objstream = Server.CreateObject("adodb.stream")
[转载]XMLHTTP 抓取[天气预报]网页内容        objstream.Type 
= 1
[转载]XMLHTTP 抓取[天气预报]网页内容        objstream.Mode 
=3
[转载]XMLHTTP 抓取[天气预报]网页内容        objstream.Open
[转载]XMLHTTP 抓取[天气预报]网页内容        objstream.Write body
[转载]XMLHTTP 抓取[天气预报]网页内容        objstream.Position 
= 0
[转载]XMLHTTP 抓取[天气预报]网页内容        objstream.Type 
= 2
[转载]XMLHTTP 抓取[天气预报]网页内容        objstream.Charset 
= Cset
[转载]XMLHTTP 抓取[天气预报]网页内容        BytesToBstr 
= objstream.ReadText 
[转载]XMLHTTP 抓取[天气预报]网页内容        objstream.Close
[转载]XMLHTTP 抓取[天气预报]网页内容        
set objstream = nothing
[转载]XMLHTTP 抓取[天气预报]网页内容
End Function
[转载]XMLHTTP 抓取[天气预报]网页内容
Function Newstring(wstr,strng)
[转载]XMLHTTP 抓取[天气预报]网页内容        Newstring
=Instr(lcase(wstr),lcase(strng))
[转载]XMLHTTP 抓取[天气预报]网页内容        
if Newstring<=0 then Newstring=Len(wstr)
[转载]XMLHTTP 抓取[天气预报]网页内容
End Function
[转载]XMLHTTP 抓取[天气预报]网页内容%
>

相关文章: