-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathget_my_friends.py
53 lines (41 loc) · 1.54 KB
/
get_my_friends.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
#-*- coding:utf-8 -*-
"""
获取自己的QQ好友列表
"""
import requests
from time import sleep
import util
class Get_friends_number(object):
'''Use to get one's friends from their qzone's entry list'''
def __init__(self):
self.headers = util.headers
self.base_url = util.parse_friends_url()
util.check_path('friends')
print('开始获取好友列表,并把文件保存到 friends 文件夹')
def get_friends(self):
key = True
position = 0
while key:
url = self.base_url + '&offset=' + str(position)
referer = 'http://qzs.qq.com/qzone/v8/pages/setting/visit_v8.html'
self.headers['Referer'] = referer
print("\tDealing with position\t%d." % position)
res = requests.get(url, headers=self.headers)
html = res.text
with open('friends/offset' + str(position) + '.json', 'w', encoding='utf-8') as f:
f.write(html)
# check whether the friend list is over
# if that, the uinlist is void list
with open('friends/offset' + str(position) + '.json', encoding='utf-8') as f2:
con = f2.read()
if "请先登录" in con:
print("登录失败,请检查原因")
key = False
break
if '''"uinlist":[]''' in con:
print("好友列表获取完毕!")
break
key = False
position += 50
sleep(5)