Skip to content

Commit 6638474

Browse files
authored
搜索api接口更新
搜索api接口更新
1 parent 809b028 commit 6638474

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

bilibili/bilibili.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def __init__(self, dirname, keyword):
1515
'Accept': '*/*',
1616
'Accept-Encoding': 'gzip, deflate, br',
1717
'Accept-Language': 'zh-CN,zh;q=0.9',
18-
'Referer': 'https://search.bilibili.com/all?keyword=%s' % parse.quote('猫')}
18+
'Referer': 'https://search.bilibili.com/all?keyword=%s' % parse.quote(keyword)}
1919

2020
self.search_headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36',
2121
'Accept-Language': 'zh-CN,zh;q=0.9',
@@ -76,7 +76,7 @@ def search_video(self, search_url):
7676
"""
7777
req = self.sess.get(url=search_url, headers=self.search_headers, verify=False)
7878
html = json.loads(req.text)
79-
videos = html['result']
79+
videos = html["data"]['result']
8080
titles = []
8181
arcurls = []
8282
for video in videos:
@@ -159,7 +159,7 @@ def search_videos(self, keyword, pages):
159159
if self.dir not in os.listdir():
160160
os.mkdir(self.dir)
161161
for page in range(1, pages+1):
162-
search_url = 'https://search.bilibili.com/api/search?search_type=video&keyword={}&order=totalrank&duration=1&tids=0&page={}'.format(keyword, page)
162+
search_url = 'https://api.bilibili.com/x/web-interface/search/type?jsonp=jsonp&search_type=video&keyword={}&page={}'.format(keyword, page)
163163
titles, arcurls = self.search_video(search_url)
164164
for index, arcurl in enumerate(arcurls):
165165
title = titles[index]

0 commit comments

Comments
 (0)