小偷程序原理和簡(jiǎn)單示例(2)_動(dòng)易Cms教程
教程Tag:暫無(wú)Tag,歡迎添加,賺取U幣!
我們拿個(gè)簡(jiǎn)單點(diǎn)的東西來(lái)研究一下吧,QQ網(wǎng)站上的天氣預(yù)告程序
程序演示地址:http://www.colasky.com/weather.asp
源碼下載:http://www.colasky.com/weather.rar
代碼如下:
| 以下是代碼片段: 〈% On Error Resume Next Server.ScriptTimeOut=9999999 Function getHTTPPage(Path) t = GetBody(Path) getHTTPPage=BytesToBstr(t,"GB2312") End function |
| 以下是代碼片段: Function GetBody(url) on error resume next Set Retrieval = CreateObject("Microsoft.XMLHTTP") With Retrieval .Open "Get", url, False, "", "" .Send GetBody = .ResponseBody End With Set Retrieval = Nothing End Function ’然后調(diào)用XMLHTTP組件創(chuàng)建一個(gè)對(duì)象并進(jìn)行初始化設(shè)置。 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 Function Newstring(wstr,strng) Newstring=Instr(lcase(wstr),lcase(strng)) if Newstring〈=0 then Newstring=Len(wstr) End Function ’處理抓取回來(lái)的數(shù)據(jù)需要調(diào)用adodb.stream組件并進(jìn)行初始化設(shè)置。%〉 ’以下即為頁(yè)面顯示部分 〈% Dim wstr,str,url,start,over,city ’定義一些需要使用到的變量 city = Request.QueryString("id") ’程序傳回的ID變量(即用戶選擇的城市)賦給id url="http://appnews.qq.com/cgi-bin/news_qq_search?city="&city&"" ’這里設(shè)置需要抓取的頁(yè)面地址,當(dāng)然你也可以直接指定某個(gè)地址而不使用變量 wstr=getHTTPPage(url) |
| 以下是代碼片段: 獲取指定頁(yè)面的全部數(shù)據(jù) start=Newstring(wstr," ") ’這里設(shè)置需要處理的數(shù)據(jù)的頭部,這個(gè)變量應(yīng)視不同情況而設(shè)置,具體內(nèi)容可以通過(guò)查看需要抓取的頁(yè)面的源代碼來(lái)確定。因?yàn)樵谶@個(gè)程序里我們需要抓取整個(gè)頁(yè)面,所以設(shè)置為頁(yè)面全部抓取。注重,設(shè)置的內(nèi)容必須是頁(yè)面內(nèi)容唯一的,不可以重復(fù)。 over=Newstring(wstr," ") ’和start相對(duì)應(yīng)的就是需要處理的數(shù)據(jù)的尾部,同樣的,設(shè)置的內(nèi)容必須是頁(yè)面中唯一的。 body=mid(wstr,start,over-start) ’設(shè)置顯示頁(yè)面的范圍 ’下面就是動(dòng)用乾坤挪移大法的時(shí)候了,通過(guò)replace可以用一些字符替換掉數(shù)據(jù)中指定的字符。 body = replace(body,"skin1","天氣預(yù)告") body = replace(body,"http://appnews.qq.com/cgi-bin/news_qq_search?city","tianqi.asp?id") ’本程序中已經(jīng)完成了替換的工作,假如有其他需要的話可以繼續(xù)進(jìn)行類似的替換操作。 response.write body %〉 |
。