forked from xiyaowong/spiders
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhaokan.py
More file actions
32 lines (26 loc) · 871 Bytes
/
Copy pathhaokan.py
File metadata and controls
32 lines (26 loc) · 871 Bytes
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
import re
import requests
def get(url: str) -> dict:
"""
title、videos
"""
data = {}
headers = {
"user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36"
}
re_title = r'<title>(.*?)</title>'
re_video = r'<video class="video" src=(.*?)></video>'
with requests.get(url, headers=headers, timeout=10) as rep:
if rep.status_code == 200:
title = re.findall(re_title, rep.text)
video = re.findall(re_video, rep.text)
if title:
data["title"] = title
if video:
data["videos"] = [video]
else:
data["msg"] = "失败"
return data
if __name__ == "__main__":
url = "https://haokan.baidu.com/v?vid=10422427972023610990&tab=recommend"
print(get(url))