這段程序的方法是利用XMLHTTP來讀取騰訊網站的相應HTML代碼獲取QQ的頭像,根據這個想法,我們還可以抓取很多其他網站的信息,如天氣預報、新聞等等。 4 ?5 U/ @7 V6 C
<script language="JavaScript">
9 {7 I- k2 Q7 Y+ V <!--
^9 t( h3 t- f8 A function getFaceImg(QQcode) ; z0 w4 z7 \! Q* ` x0 K
{ - Q: f+ o$ K$ j# Y& D& H7 U' j
var Re=new RegExp("^[1-9]{1}\d+$","g"); * \# U9 k* W# y4 h
if (!QQcode !Re.test(QQcode)) return; ; b L& T5 b+ K+ w l, S
var URL="http://search.tencent.com/cgi-bin/friend/oicq_find?oicq_no="+QQcode; ) y& {- {& \+ d9 f5 [ R$ ~ s
var http=new ActiveXObject("Microsoft.XMLHTTP"); * `& g9 f) C, H2 _: }. L5 x$ x
http.open("GET",URL,false,"","");
# F( i$ g- c8 V n m, V7 E http.setRequestHeader("CONTENT-TYPE","text/html; Charset=gb2312"); . @: p0 I$ R! A6 j1 q Y
http.send(); 5 Q. `$ P) @( t9 k
$ _* O& d q( S( A7 ~# R8 E if (http.status!=200) return;
6 _% l8 X9 J2 T1 O ~5 C9 q2 E- e
) m$ m. ~* C" B var webStr=http.responseText;
8 k6 [ V1 W7 ~ Re=new RegExp(""(http://img.tencent.com/face/[^"]+)"","ig");
% v2 N$ ~" W3 L* U* g if (Re.test(webStr))
) e/ |% U' M' G2 \ 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>"; 9 v. a* W$ H# u5 \
9 {2 v" }; P5 |, @5 J. s http=null;
& U' m" K( ]% S& @5 s }
7 k {: d4 X9 x# l& x' a+ t$ `( R0 U7 ~" v; R& [$ D3 j% s; n$ B
document.write("我的QQ狀態:"+getFaceImg("44723461"));
) {8 t: L! z4 W //--> . y5 @9 S& Z# u: ]4 i2 ~* N
</script> |
|