1. 程式人生 > >Python 3 中檢測QQ線上的指令碼

Python 3 中檢測QQ線上的指令碼

近期在學習python ,在論壇上看到一些qq 狀態的測試,但都是python 2.7的版本,為此在python3 中實現一次,以便日後複習使用

import time,datetime
from urllib.request import urlopen
def chk_qq(qqnum):
chkurl = 'http://wpa.qq.com/pa?p=1:'+str(qqnum)+':1'
print(chkurl)
a = urlopen(chkurl)
length=a.headers.get("content-length")
a.close()
print (datetime.datetime.now() )
if length=='2329':
return 'Online'
elif length=='2262':
return 'Offline'
else:
return 'Unknown Status!'

qq = 595787398
stat = chk_qq(qq)
print (str(qq) + ' is ' + stat)