<%
On Error Resume Next
Function RemoveHTML(strHTML)
Dim objRegExp, Match, Matches
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
'取闭合的<>
objRegExp.Pattern = "<.+?>"
'进行匹配
Set Matches = objRegExp.Execute(strHTML)
' 遍历匹配集合,并替换掉匹配的项目
For Each Match in Matches
strHtml=Replace(strHTML,Match.Value,"")
Next
RemoveHTML=strHTML
Set objRegExp = Nothing
End Function
'判断数据库里是否有当天的天气预报
'如果没有,就读取未能远程数据并保存在数据库内
'声明一个函数,用于读取远程文件
function getHTTPPage(url)
dim Http
set Http=server.createobject("MSXML2.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
exit function
end if
getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
set http=nothing
if err.number<>0 then err.Clear
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
'要偷的网页的地址,你只需要从http://www.weathercn.com/找到你要偷取的页面就行
Url="http://weather.news.qq.com/inc/ss248.htm"
Html = getHTTPPage(Url) '开始读取远程地址
Html2=RemoveHTML(Html)
'搜索要偷取的内容的开始位置
tqStr_start = instr(Html2,"A.color4:hover { COLOR: #DD7D02;TEXT-DECORATION: underline}")
tqStr_end = instr(Html2,"function")+1
Html1 = Mid(Html2,tqStr_start+59,tqStr_end-305)
Html3 = ""&Html1&""
Html4=replace(Html3,"合肥","合肥天气")
%>
今日 <%=Html4%>
本文作者:佚名 来源:本站原创
CIO之家 www.ciozj.com 微信公众号:imciow