-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBiliBili.py
More file actions
93 lines (86 loc) · 2.24 KB
/
Copy pathBiliBili.py
File metadata and controls
93 lines (86 loc) · 2.24 KB
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
91
92
93
import sys
import requests
import time
import json
import csv
import datetime
pop_web = 'https://api.bilibili.com/x/web-interface/popular'
header = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.1370.42",
"Reffer": "https://www.bilibili.com/",
"cookie": "sth",
}
def GetList(PopList=[]):
for i in range(1, 4):
param = {'ps': '20', 'pn': i}
content = requests.get(url=pop_web, headers=header, params=param)
content.close()
PopList = PopList + json.loads(content.text)['data']['list']
return PopList
def Form(PopInfo):
global ProcessData
title = PopInfo['title']
link = PopInfo['short_link']
owner = PopInfo['owner']['name']
pubinfo = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(PopInfo['pubdate']))
desc = PopInfo['desc']
if desc == '-' or desc == '':
desc = 'None'
stat = PopInfo['stat']
view = stat['view']
like = stat['like']
share = stat['share']
subtitle = stat['danmaku']
favorite = stat['favorite']
coin = stat['coin']
tname = PopInfo['tname']
feature = PopInfo['rcmd_reason']['content']
if feature == '':
feature = 'None'
ProcessData.append(
{
'标题': title,
'链接': link,
'UP': owner,
'分区': tname,
'稿件上传时间': pubinfo,
'简介': desc,
'播放量': view,
'点赞数': like,
'硬币数': coin,
'收藏数': favorite,
'分享数': share,
'弹幕数': subtitle,
'TAG': feature,
}
)
HeadData = [
'标题',
'链接',
'UP',
'分区',
'稿件上传时间',
'简介',
'播放量',
'点赞数',
'硬币数',
'收藏数',
'分享数',
'弹幕数',
'TAG',
]
PopList = GetList()
ProcessData = []
for i in PopList:
Form(i)
with open(
'{}/../data/热门{}.csv'.format(
sys.path[0], datetime.datetime.now().strftime("%Y-%m-%d")
),
'w',
encoding='utf-8-sig',
newline='',
) as f:
writer = csv.DictWriter(f, HeadData)
writer.writeheader()
writer.writerows(ProcessData)