這段程序的方法是利用XMLHTTP來讀取騰訊網站的相應HTML代碼獲取QQ的頭像,根據這個想法,我們還可以抓取很多其他網站的信息,如天氣預報、新聞等等。
Q# u" @( {0 Y' g0 @<script language="JavaScript">
4 p e. s" R! {( [ d8 I* D2 h <!--
4 l; Q5 d) m& K; H function getFaceImg(QQcode)
6 j3 G: i# D- a6 [ { ( `$ U/ @- L7 R2 a) v/ h9 p+ k
var Re=new RegExp("^[1-9]{1}\d+$","g"); 1 a" Z# j, _5 ~( W8 |
if (!QQcode !Re.test(QQcode)) return; " ]3 L' Y' q% \5 N
var URL="http://search.tencent.com/cgi-bin/friend/oicq_find?oicq_no="+QQcode; 9 X" D( @) q, a
var http=new ActiveXObject("Microsoft.XMLHTTP");
( U2 ~1 e# e' Y* R' I( f http.open("GET",URL,false,"","");
% W& |! T$ O, a http.setRequestHeader("CONTENT-TYPE","text/html; Charset=gb2312"); 2 m9 I8 t: u: l- J
http.send(); # _: q& m9 y2 a; x+ e# o* T v
# N( _7 `4 w1 ~( v: h% g7 } if (http.status!=200) return; ' i# d% @, X. Q; d: k/ `! v! Y
8 H, S9 {3 b8 v# _" q$ m var webStr=http.responseText; 2 E, F$ c' \! l: U, b- Y3 j
Re=new RegExp(""(http://img.tencent.com/face/[^"]+)"","ig"); ' l" h. K+ z$ m$ [3 b
if (Re.test(webStr))
3 \$ L1 g% l3 v/ w3 k return "<a href="http://search.tencent.com/cgi-bin/friend/user_show_info?ln="+QQcode+"" target=_blank title="QQ:"+QQcode+""><img src=""+RegExp.$1+"" width=16 height=16 border=0></a>"; 0 Z" o3 {" O% W' G& G) ?4 L; \
; N4 H0 T, R0 H3 u+ n# G
http=null; * ^' F, m4 d7 Q; G1 c
} # U" X& z% [) Z V6 _. Y* O
! P J/ | Y& b9 u' L2 c
document.write("我的QQ狀態:"+getFaceImg("44723461"));
( j+ s' _$ w% v- R; W8 N% X, K //-->
# |6 _3 M, w6 K2 w2 }: C" y- E </script> |
|