实例解析抓取天气预报的程序

ASP教程 2025-08-30

推荐:ASP返回某字符串最后出现的位置% dwwwStr= divdwww.cn/divdivwww.dwww.cn/div设计家园 dwwwStr= InStrRev(dwwwStr,/div) response.write dwwwStr % InstrRev 描述 返回某字符串在另一个字符串中出现的从结尾计起的位置。 语法 InstrRev(string1, string2[, start[, compare]]) InstrRe

早上在公司上班的时候,看到外边下起了雪,2008年的第一场雪,比以往来的更晚一点,呵呵,冷啊。。

于是想办法写抓天气预报的程序,看到了QQ的天气预报挺不错的。。呵呵。。就抓你了!

如图:

代码:

<%

'On Error Resume Next

'作者:无情 来源: 转载请保留出处

Response.ContentType=text/html; charset=gb2312

Call weather()

Sub weather()

url=http://weather.**news.*qq.com/inc/07_ss252.htm '上海的天气

Call IsObjInstalled(Microsoft.XMLHTTP)

weatherStr= getHTTPPage(url)

if weatherStr= then

response.write 抱歉,天气预报加载失败!

else

set reg=new Regexp

reg.Multiline=True

reg.Global=false

reg.IgnoreCase=true

reg.Pattern=((.|/n)*?)

Set matches = reg.execute(weatherStr)

For Each match1 in matches

weatherStr=match1.Value

Next

Set matches = Nothing

Set reg = Nothing

if InStr(weatherStr,没有找到与)>0 then

response.write 抱歉,天气预报加载失败!

Else

weatherStr=Replace(weatherStr,,)

weatherStr=Replace(weatherStr,

,)

weatherStr=Replace(weatherStr,

, )

weatherStr=Replace(weatherStr,,)

response.write 上海天气预报:&weatherStr&

end if

end if

End Sub

'// 采用 Microsoft.XMLHTTP 组件采集数据

Function getHTTPPage(url)

'on error resume next

dim http

set http=Server.createobject(Microsoft.XMLHTTP)

Http.open GET,url,false

Http.send()

if Http.readystate<>4 then

exit function

end if

getHTTPPage=bytes2BSTR(Http.responseBody)

set http=nothing

if err.number<>0 then err.Clear

End function

分享:解析Asp实现Dig程序中的投票ASP做一个dig程序中的投票(有的叫顶一下,踩一下),由于代码较长,只贴出核心部分:投票中的代码 网页显示投票的部分: div class=Vote1script src='/voteResult.asp?id=1action=view'/script/div 效果如图: 520)this.width=500 border=0>,然后点投一

共2页上一页12下一页