用Asp實現(xiàn)QQ在線查詢功能

2010-08-28 10:45:31來源:西部e網(wǎng)作者:

    這段程序的方法是利用XMLHTTP來讀取騰訊網(wǎng)站的相應HTML代碼獲取QQ的頭像,根據(jù)這個想法,我們還可以抓取很多其他網(wǎng)站的信息,如天氣預報、新聞等等。

提示:請把“<>”轉(zhuǎn)換為“<>”

<script language="JavaScript">
<!--
function getFaceImg(QQcode)
{
var Re=new RegExp("^[1-9]{1}\\d+$","g");
if (!QQcode  !Re.test(QQcode)) return;
var URL="http://search.tencent.com/cgi-bin/friend/oicq_find?oicq_no="+QQcode;
var http=new ActiveXObject("Microsoft.XMLHTTP");
http.open("GET",URL,false,"","");
http.setRequestHeader("CONTENT-TYPE","text/html; Charset=gb2312");
http.send();

if (http.status!=200) return;

var webStr=http.responseText;
Re=new RegExp("\"(http://img.tencent.com/face/[^\"]+)\"","ig");
if (Re.test(webStr))
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>";

http=null;
}

document.write("我的QQ狀態(tài):"+getFaceImg("12345678"));
//-->
</script>
關鍵詞:Asp