-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbili.py
42 lines (34 loc) · 1.29 KB
/
bili.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
# -*- coding:utf-8 -*-
from bs4 import BeautifulSoup
from urllib import request
from global_info import *
# bilibili.com - structure
# <ul class="video-list clearfix">
# <div class="info"> * n
# <a class="title" href="//www.bilibili.com/video/?seid=13107056418744793102">
# <span class="tag-item uper">
# ------- or -------
# <div class="video i_wrapper search-all-list">
# <div class="video-list row">
# <div class="bili-video-card"> * n
# <div class="bili-video-card__info--right">
# <a href="//www.bilibili.com/video/BV1Af421X7Kg/"> title
# <p class="bili-video-card__info--bottom"> author
def search(query):
req = request.Request(
url = f"https://search.bilibili.com/all?keyword={query}",
headers = headers
)
html = request.urlopen(req).read().decode('utf8')
soup = BeautifulSoup(html, 'html.parser')
body = soup.find("ul", "video-list clearfix")
for div in body.find_all("div", "info"):
a = div.find("a", "title")
title = a.get_text()
link = a["href"]
uper = div.find("span", "tag-item uper").get_text()
if uper in title:
print(title)
else:
print(f"{title} - ({uper})")
print("-----------------------------")