-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch_sina_fans.py
45 lines (37 loc) · 1.15 KB
/
fetch_sina_fans.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
import requests
import re
import utils
TAG = 'sina_fans'
cookie = '##'
header = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Encoding': 'gzip, deflate, sdch',
'Accept-Language': 'zh-CN,zh;q=0.8,en;q=0.6,zh-TW;q=0.4',
'Cache-Control': 'max-age=0',
'Connection': 'keep-alive',
'Cookie': cookie,
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.98 Safari/537.36'
}
def log(msg):
utils.log(utils.log_level_debug, TAG, msg)
def sina_fans(url):
result = {
}
if not url:
return result
log(url)
try:
resp = requests.get(url, headers=header, timeout=10)
log(resp.status_code)
if resp.status_code == 200:
page = resp.content.decode('utf-8')
fans = re.findall(r'W_f18\\\">(\d+)<\\/strong><span class=\\\"S_txt2\\\">粉丝', page)
log(fans)
if fans:
result = {
'url': url,
'fans': str(fans[0])
}
except Exception as ex:
log(ex)
return result