實(shí)例解析抓取天氣預(yù)報(bào)的程序_ASP教程
推薦:ASP返回某字符串最后出現(xiàn)的位置% dwwwStr= divdwww.cn/divdivwww.dwww.cn/div設(shè)計(jì)家園 dwwwStr= InStrRev(dwwwStr,/div) response.write dwwwStr % InstrRev 描述 返回某字符串在另一個(gè)字符串中出現(xiàn)的從結(jié)尾計(jì)起的位置。 語法 InstrRev(string1, string2[, start[, compare]]) InstrRe
早上在公司上班的時(shí)候,看到外邊下起了雪,2008年的第一場(chǎng)雪,比以往來的更晚一點(diǎn),呵呵,冷啊。。
于是想辦法寫抓天氣預(yù)報(bào)的程序,看到了QQ的天氣預(yù)報(bào)挺不錯(cuò)的。。呵呵。。就抓你了!
如圖:
代碼:
<%
'On Error Resume Next
'作者:無情 來源: 轉(zhuǎn)載請(qǐng)保留出處
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 "抱歉,天氣預(yù)報(bào)加載失敗!"
else
set reg=new Regexp
reg.Multiline=True
reg.Global=false
reg.IgnoreCase=true
reg.Pattern="<td height=""77"" class=""wht2 lk37"">((.|\n)*?)</td>"
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 "抱歉,天氣預(yù)報(bào)加載失敗!"
Else
weatherStr=Replace(weatherStr,"<td height=""77"" class=""wht2 lk37"">","")
weatherStr=Replace(weatherStr,"<div class=""txbd"">","")
weatherStr=Replace(weatherStr,"</div>"," ")
weatherStr=Replace(weatherStr,"</td>","")
response.write "上海天氣預(yù)報(bào):"&weatherStr&""
end if
end if
End Sub
'// 采用 Microsoft.XMLHTTP 組件采集數(shù)據(jù) 分享:解析Asp實(shí)現(xiàn)Dig程序中的投票ASP做一個(gè)dig程序中的投票(有的叫頂一下,踩一下),由于代碼較長(zhǎng),只貼出核心部分:投票中的代碼 網(wǎng)頁顯示投票的部分: div class=Vote1script src='/voteResult.asp?id=1action=view'/script/div 效果如圖: 520)this.width=500 border=0>,然后點(diǎn)投一
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 FSO 讀寫文件本文件實(shí)現(xiàn)代碼
- asp中isNull、isEmpty和空字符串的區(qū)別
- asp獲取用戶真實(shí)IP地址的方法
- asp連接sqlserver數(shù)據(jù)庫實(shí)現(xiàn)代碼
- asp中正則表達(dá)式過濾html代碼函數(shù)
- asp中g(shù)et post提交表單區(qū)別
- 網(wǎng)頁模板:ASP內(nèi)建對(duì)象Request
- xmlhttp的open方法使用詳解
- ASP的常用的自定義函數(shù)大全
- asp中用for循環(huán)的一個(gè)小技巧
- eWebEditor v3.8 列目錄
- ASP無組件分頁實(shí)現(xiàn)思路及代碼
- 相關(guān)鏈接:
- 教程說明:
ASP教程-實(shí)例解析抓取天氣預(yù)報(bào)的程序
。