ADD file via upload

main
py6qo2c5g 2 months ago
parent 73478149ed
commit 3b8b572b09

@ -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
Loading…
Cancel
Save