def getFriend(self): try: url = 'http://s.web2.qq.com/api/get_user_friends2' import getFriend2_hash cnt = 1 while self.uin_user[cnt] == '0': cnt += 1 ptwebqq_hash = getFriend2_hash.getFriend2_hash2(self.uin_user[cnt:], self.ptwebqq) print ptwebqq_hash #data = 'r=%7B%22vfwebqq%22%3A%22'+self.result['result']['vfwebqq'] +'%22%7D' data = ('r=%7B%22h%22%3A%22hello%22%2C%22hash%22%3A%22' +ptwebqq_hash+'%22%2C%22vfwebqq%22%3A%22' +self.result['result']['vfwebqq']+'%22%7D') req = urllib2.Request(url, data) req.add_header('Referer', 'http://s.web2.qq.com/proxy.html?v=20110412001&callback=1&id=1') print 'ptwebqq=' + self.ptwebqq print data req = urllib2.urlopen(req) self.friend_ret = json.load(req) self.uin = dict() self.markname = dict() self.nick = dict() self.cat = dict() self.friend = self.friend_ret['result']['friends'] self.categories = self.friend_ret['result']['categories'] for fri in self.friend: self.cat[fri['uin']] = fri['categories'] for info in self.friend_ret['result']['info']: self.nick[info['nick']] = info['uin'] self.uin[info['uin']] = info['nick'] for mark in self.friend_ret['result']['marknames']: self.markname[mark['markname']] = mark['uin'] self.uin[mark['uin']] = mark['markname'] print '好友信息拉取成功!' self.success_login = True #with open('res/login_cookie', 'w') as f: # f.write(str(self.cookies)) self.cookies.save('res/getFriend.cookie') except Exception as e: cnt = 1 while self.uin_user[cnt] == '0': cnt += 1 import getFriend2_hash ptwebqq_hash = getFriend2_hash.getFriend2_hash2(self.uin_user[cnt:], self.ptwebqq) data = ('r=%7B%22h%22%3A%22hello%22%2C%22hash%22%3A%22' +ptwebqq_hash+'%22%2C%22vfwebqq%22%3A%22' +self.result['result']['vfwebqq']+'%22%7D') print 'ptwebqq=' + self.ptwebqq print data print '获取列表失败,重试中...' print self.friend_ret print e while not self.getFriend_2(): self.getFriend_2() else: pass
def getFriend(self): try: url = 'http://s.web2.qq.com/api/get_user_friends2' import getFriend2_hash cnt = 1 while self.uin_user[cnt] == '0': cnt += 1 ptwebqq_hash = getFriend2_hash.getFriend2_hash4(self.uin_user[cnt:], self.ptwebqq) #data = 'r=%7B%22vfwebqq%22%3A%22'+self.result['result']['vfwebqq'] +'%22%7D' data = ('r=%7B%22h%22%3A%22hello%22%2C%22hash%22%3A%22' +ptwebqq_hash+'%22%2C%22vfwebqq%22%3A%22' +self.result['result']['vfwebqq']+'%22%7D') req = urllib2.Request(url, data) req.add_header('Referer', 'http://s.web2.qq.com/proxy.html?v=20110412001&callback=1&id=1') print 'ptwebqq=' + self.ptwebqq print data req = urllib2.urlopen(req) self.friend_ret = json.load(req) self.uin = dict() self.markname = dict() self.nick = dict() self.cat = dict() self.friend = self.friend_ret['result']['friends'] self.categories = self.friend_ret['result']['categories'] for fri in self.friend: self.cat[fri['uin']] = fri['categories'] for info in self.friend_ret['result']['info']: self.nick[info['nick']] = info['uin'] self.uin[info['uin']] = info['nick'] for mark in self.friend_ret['result']['marknames']: self.markname[mark['markname']] = mark['uin'] self.uin[mark['uin']] = mark['markname'] print '好友信息拉取成功!' self.success_login = True #with open('res/login_cookie', 'w') as f: # f.write(str(self.cookies)) self.cookies.save('res/getFriend.cookie') except Exception as e: cnt = 1 while self.uin_user[cnt] == '0': cnt += 1 import getFriend2_hash ptwebqq_hash = getFriend2_hash.getFriend2_hash2(self.uin_user[cnt:], self.ptwebqq) data = ('r=%7B%22h%22%3A%22hello%22%2C%22hash%22%3A%22' +ptwebqq_hash+'%22%2C%22vfwebqq%22%3A%22' +self.result['result']['vfwebqq']+'%22%7D') print 'ptwebqq=' + self.ptwebqq print data print '获取列表失败,重试中...' print self.friend_ret print e while not self.getFriend_2(): self.getFriend_2() else: pass
def getFriend_2(self): try: cnt = 1 while self.uin_user[cnt] == '0': cnt += 1 import requests url = 'http://s.web2.qq.com/api/get_user_friends2' headers = { 'Referer': 'http://s.web2.qq.com/proxy.html?v=20110412001&callback=1&id=1' } import getFriend2_hash ptwebqq_hash = getFriend2_hash.getFriend2_hash2( self.uin_user[cnt:], self.ptwebqq) data = ('r=%7B%22h%22%3A%22hello%22%2C%22hash%22%3A%22' + ptwebqq_hash + '%22%2C%22vfwebqq%22%3A%22' + self.result['result']['vfwebqq'] + '%22%7D') cookies = dict(ptwebqq=str(self.ptwebqq)) req = requests.post(url, cookies=cookies, data=data, headers=headers) #req = requests.post(url,data = data, headers = headers) self.friend_ret = json.loads(req.content) self.uin = dict() self.markname = dict() self.nick = dict() self.cat = dict() self.friend = self.friend_ret['result']['friends'] self.categories = self.friend_ret['result']['categories'] for fri in self.friend: self.cat[fri['uin']] = fri['categories'] for info in self.friend_ret['result']['info']: self.nick[info['nick']] = info['uin'] self.uin[info['uin']] = info['nick'] for mark in self.friend_ret['result']['marknames']: self.markname[mark['markname']] = mark['uin'] self.uin[mark['uin']] = mark['markname'] print '好友信息拉取成功!' self.success_login = True return True #with open('res/login_cookie', 'w') as f: # f.write(str(self.cookies)) except Exception as e: print e print self.friend_ret
def getFriend_2(self): try: cnt = 1 while self.uin_user[cnt] == '0': cnt += 1 import requests url = 'http://s.web2.qq.com/api/get_user_friends2' headers = {'Referer': 'http://s.web2.qq.com/proxy.html?v=20110412001&callback=1&id=1'} import getFriend2_hash ptwebqq_hash = getFriend2_hash.getFriend2_hash2(self.uin_user[cnt:], self.ptwebqq) data = ('r=%7B%22h%22%3A%22hello%22%2C%22hash%22%3A%22' +ptwebqq_hash+'%22%2C%22vfwebqq%22%3A%22' +self.result['result']['vfwebqq']+'%22%7D') cookies = dict(ptwebqq=str(self.ptwebqq)) req = requests.post(url, cookies = cookies, data = data, headers = headers) #req = requests.post(url,data = data, headers = headers) self.friend_ret = json.loads(req.content) self.uin = dict() self.markname = dict() self.nick = dict() self.cat = dict() self.friend = self.friend_ret['result']['friends'] self.categories = self.friend_ret['result']['categories'] for fri in self.friend: self.cat[fri['uin']] = fri['categories'] for info in self.friend_ret['result']['info']: self.nick[info['nick']] = info['uin'] self.uin[info['uin']] = info['nick'] for mark in self.friend_ret['result']['marknames']: self.markname[mark['markname']] = mark['uin'] self.uin[mark['uin']] = mark['markname'] print '好友信息拉取成功!' self.success_login = True return True #with open('res/login_cookie', 'w') as f: # f.write(str(self.cookies)) except Exception as e: print e print self.friend_ret