forked from xjr7670/QQzone_crawler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.py
90 lines (70 loc) · 2.73 KB
/
util.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from urllib import parse
import os
def get_cookie():
'''Get cookie from cookie_file'''
with open('cookie_file') as f:
cookie = f.read()
cookie = cookie.replace('\n', '')
return cookie
cookie = get_cookie()
headers = {'host': 'h5.qzone.qq.com',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'zh,zh-CN;q=0.8,en-US;q=0.5,en;q=0.3',
'Accept-Encoding': 'gzip, deflate, br',
'Cookie': cookie,
'connection': 'keep-alive'}
def get_g_tk():
''' make g_tk value'''
pskey_start = cookie.find('p_skey=')
pskey_end = cookie.find(';', pskey_start)
p_skey = cookie[pskey_start+7: pskey_end]
h = 5381
for s in p_skey:
h += (h << 5) + ord(s)
return h & 2147483647
g_tk = get_g_tk()
def parse_moods_url(qqnum):
'''This method use to get every friend's mood cgi url
So it needs the friend's qqnumber to get their url
'''
params = {"cgi_host": "http://taotao.qq.com/cgi-bin/emotion_cgi_msglist_v6",
"code_version": 1,
"format": "jsonp",
"g_tk": g_tk,
"hostUin": qqnum,
"inCharset": "utf-8",
"need_private_comment": 1,
"notice": 0,
"num": 20,
"outCharset": "utf-8",
"sort": 0,
"uin": qqnum}
host = "https://h5.qzone.qq.com/proxy/domain/taotao.qq.com/cgi-bin/emotion_cgi_msglist_v6?"
url = host + parse.urlencode(params)
return url
def parse_friends_url():
'''This method only generate the friends of the owner
So do not need to get qq number, just get it from
self cookie
'''
cookie = headers['Cookie']
qq_start = cookie.find('uin=o')
qq_end = cookie.find(';', qq_start)
qqnumber = cookie[qq_start+5 : qq_end]
if qqnumber[0] == 0:
qqnumber = qqnumber[1:]
params = {"uin": qqnumber,
"fupdate": 1,
"action": 1,
"g_tk": g_tk}
host = "https://h5.qzone.qq.com/proxy/domain/base.qzone.qq.com/cgi-bin/right/get_entryuinlist.cgi?"
#https://h5.qzone.qq.com/proxy/domain/base.qzone.qq.com/cgi-bin/right/get_entryuinlist.cgi?uin=284182470&fupdate=1&action=1&offset=200&g_tk=1350570173&qzonetoken=8114052f3d145601114b9b3f8caad4ad2853b418b9c345f42af296d6d3e2c980b592a1b7c52273aaa0
url = host + parse.urlencode(params)
return url
def check_path(path):
'''This method use to check if the path is exists.
If not, create that
'''
if not os.path.exists(path):
os.mkdir(path)