Home  >  Article  >  Backend Development  >  Python检测QQ在线状态的方法

Python检测QQ在线状态的方法

WBOY
WBOYOriginal
2016-06-10 15:12:581120browse

本文实例讲述了Python检测QQ在线状态的方法。分享给大家供大家参考。具体实现方法如下:

import time,datetime  
import urllib2 
def chk_qq(qqnum):
  chkurl = 'http://wpa.paipai.com/pa?p=1:'+`qqnum`+':17'
  a = urllib2.urlopen(chkurl)  
  length=a.headers.get("content-length")  
  a.close()  
  print datetime.datetime.now()
  print length 
  if length=='2348':  
    return 'Online' 
  elif length=='2205':  
    return 'Offline' 
  else:  
    return 'Unknown Status!' 
def writestate(statenow):
  f=open(str(qq),'a')
  m=str(datetime.datetime.now())+"===state===="+statenow+"\n\r"
  f.write(m)
  f.close()
qq = 847893543
##state=1
if __name__=='__main__':
  while 1:
    stat = chk_qq(qq)
    writestate(stat)
    time.sleep(6000) ##5分钟测一次
    print `qq` + ' is ' + stat

希望本文所述对大家的Python程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn