python 爬取QQ群中的会员QQ号码


好久没有用爬虫了,手有点生,找了一段代码,但是发现有BUG,还得自己修复。
import requests
import browsercookie
import random,time
from copyheaders import headers_raw_to_dict

headers_raw = b'''
authority: qun.qq.com
method: POST
path: /cgi-bin/qun_mgr/search_group_members
'''
headers = headers_raw_to_dict(headers_raw)

class QQ(object):
def __init__(self,gc,bkn,num,headers):
self.headers = headers
self.gc = gc
self.bkn = bkn
self.num = num//40 + 1
self.url = 'https://qun.qq.com/cgi-bin/qun_mgr/search_group_members'

def qqs(self):
qqs = []
for i in range(self.num):
num1 = i * 40
num2 = (i + 1) * 40
data = {'gc': self.gc,
'st': '{}'.format(num1),
'end': '{}'.format(num2),
'sort': '0',
'bkn': self.bkn
}
res = requests.post(self.url, data=data, headers=self.headers, cookies = cookies).json()
print(res)
time.sleep(random.uniform(2, 3.5))
members = res['mems']
for line in members:
qq = line.get('uin', 85***7)
nick = line.get('nick','未知')
qq_data = '{}t{}'.format(nick,qq)
print(qq_data)
qqs.append(qq_data)
return qqs

def save_qqs(self):
qqs = self.qqs()
with open('qqs.txt','w',encoding='utf-8-sig') as f:
f.writelines([qq+'n' for qq in qqs])

# 三个参数,即QQ群号gc,bkn值,群成员个数,请求头;其中gc、bkn在荷载中可以查到
qq = QQ('60***5','20***103',1945,headers)
qq.save_qqs()

可以看到QQ号,昵称、加入群时间,最后发言时间,这4个数据有用!在一个项目做种子用户的时候,QQ群仍是一个有利的工具。

未经允许不得转载:选主机测评网 » python 爬取QQ群中的会员QQ号码