网络请求-抓取qq群好友信息 day07-10

import requests,xlwt
import random
url = "https://qun.qq.com/cgi-bin/qun_mgr/get_friend_list"
data = {"bkn": "534039"}
cookie = {"cookis":"RK=vswpWpGmTk; ptcz=bd1799a527a599bc9ac29a7754005b0b0cc4861f99dc2ebd8ad761e11e495851; "
"pgv_pvid=7249439792; pgv_pvi=1512488960; tvfe_boss_uuid=0fa9ae31c8683d6d; o_cookie=1195665307; "
"pac_uid=1_1195665307; eas_sid=L1b6y1l5A848p1O5w1U4n0N5y6; "
"__guid=14431543.4441650296924942000.1618218798379.9321; "
"BIDUPSID=BCA0C1388E2472ADF8CABB90D8440461; PSTM=1618304933; "
"BAIDUID=89BCC6DF2C355C4FA2DB4DEE79781652:FG=1; iip=0; traceid=4b7848e787; "
"_qpsvr_localtk=0.5216509271880581; uin=o1195665307; skey=@hULH9H6Ln; p_uin=o1195665307; "
"pt4_token=lz60j2a3Vf-SBesAtJsRa8PVlENmw0L-6LHigCoLJAY_; "
"p_skey=Gfbliy1ruJfkeTgZ-boOejCqGM1iQhYsftVulkX3r4g_; monitor_count=9"}
res = requests.post(url,data,cookies = cookie)

result = res.json().get("result")
print(result)
book = xlwt.Workbook()
for index,g_info in result.items():
g_mems = g_info.get('mems')
g_name = g_info.get("gname") if g_info.get("gname") else "默认分组"
print("当前取的分组是===============",g_name)
try:
sheet = book.add_sheet(g_name)
except Exception as e:
sheet_name = "好友分组_%s" % random.randint(1,1000)
print("sheet页名字不合法,请重新命名" )
sheet = book.add_sheet(sheet_name)
for col,mem in enumerate(g_mems):
nick = mem.get("name")
qq = mem.get("uin")
sheet.write(col,0,nick)
sheet.write(col,1,qq)
# print("%s => %s" % (nick,qq))

book.save("qq.xls")
上一篇:网络请求request day07-11


下一篇:零基础入门学习JAVA课堂笔记 ——DAY07