-
Notifications
You must be signed in to change notification settings - Fork 0
/
up_fans.py
61 lines (49 loc) · 1.77 KB
/
up_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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import requests as rq
import os, random
import pandas as pd
df=pd.read_csv('bili_fans/up_fans_new.csv',index_col=[0])
# df=pd.DataFrame(index=['mid'])
cookie=os.environ["XZ_COOKIE"]
header={"Host": "xz.newrank.cn"
,"Connection": "keep-alive"
,"Content-Length": "90"
,"Accept": "application/json, text/plain, */*"
,"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/,87.0.4280.88 Safari/537.36"
,"Content-Type": "application/json;charset=UTF-8"
,"Origin": "https://xz.newrank.cn"
,"Sec-Fetch-Site": "same-origin"
,"Sec-Fetch-Mode": "cors"
,"Sec-Fetch-Dest": "empty"
,"Accept-Encoding": "gzip, deflate, br"
,"Accept-Language": "zh-CN,zh;q=0.9"
,"Cookie": cookie
}
a={"indexType":0,"field":"","sort":"addFollowerCount","interval":"day","size":60,"start":1}
def proc(da,date):
for i in da:
num=i['addFollowerCount'].replace("-","")
if 'w' in num:
num=num.replace("w",'')
num=eval(num)*10000+random.randint(1,100)
if i['name'] not in df.columns:
df[i['name']]=[0]*len(df.index)
df[i['name']]['mid']=i['mid']
if date not in df.index.tolist():
df.loc[date]=[0]*len(df.columns)
df[i['name']][date]=int(num)
# up_pic(i['face'],i['mid'])
print(f"{i['name']}=={num}")
# def up_pic(url,mid):
# if not os.path.exists(f"up_pic/{mid}.jpg"):
# pic=rq.get(url,headers=header1).content
# with open(f'up_pic/{mid}.jpg','wb') as f:
# f.write(pic)
def spider_all_day():
res=rq.post("https://xz.newrank.cn/nr/bili/rank/singleIndex",json=a,headers=header).json()['data']
date=res['update_time'].split(" ")[0]
proc(res['list'],date)
def main():
spider_all_day()
df.to_csv('bili_fans/up_fans_new.csv',index=True,header=True)
if __name__ == '__main__':
main()