近期在学习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)