forked from xiyaowong/spiders
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxiaokaxiu.py
More file actions
44 lines (35 loc) · 1.22 KB
/
xiaokaxiu.py
File metadata and controls
44 lines (35 loc) · 1.22 KB
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
42
43
44
# @wongxy
import time
from hashlib import md5
from urllib.parse import urlparse, parse_qs
import requests
def get(url: str) -> dict:
"""
title、videos
"""
data = {}
try:
qs = parse_qs(urlparse(url).query)
video_id = qs["id"][0]
except KeyError:
return {"msg": "无法匹配视频id"}
timestamp = str(int(time.time()))
info_url = "https://appapi.xiaokaxiu.com/api/v1/web/share/video/" + video_id + "?time=" + timestamp
temp = "S14OnTD#Qvdv3L=3vm" + "&time=" + timestamp
x_sign = md5(temp.encode("utf-8")).hexdigest()
headers = {
"user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36",
"x-sign": x_sign,
}
rep = requests.get(info_url, headers=headers)
if rep.status_code == 200 and rep.json()["code"] == 0:
video_info = rep.json()["data"]
title = video_info["video"]["title"]
video_url = video_info["video"]["url"][0]
data["title"] = title
data["videos"] = [video_url]
return data
return {"msg": "获取失败"}
if __name__ == "__main__":
url = "https://mobile.xiaokaxiu.com/video?id=6552158363189252096"
print(get(url))