From 3b8b572b09a0ee1f0fd3d59fdf5c5d2a601ee715 Mon Sep 17 00:00:00 2001 From: py6qo2c5g <457171044@qq.com> Date: Wed, 18 Sep 2024 18:47:14 +0800 Subject: [PATCH] ADD file via upload --- one.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 one.py diff --git a/one.py b/one.py new file mode 100644 index 0000000..eda73ef --- /dev/null +++ b/one.py @@ -0,0 +1,22 @@ +import requests +from bs4 import BeautifulSoup + + +def get_video_ids(keyword, num_videos): + video_ids = [] + page_num = (num_videos - 1) // 20 + 1 + base_url = "https://search.bilibili.com/all?keyword={}&order=totalrank&duration=0&tids_1=0&page={}" + for page in range(1, page_num + 1): + url = base_url.format(keyword, page) + response = requests.get(url) + soup = BeautifulSoup(response.text, 'html.parser') + video_tags = soup.find_all('li', {'class': 'video-item matrix'}) + for tag in video_tags: + video_id = tag.get('data - aid') + if video_id: + video_ids.append(video_id) + if len(video_ids) >= num_videos: + break + if len(video_ids) >= num_videos: + break + return video_ids