video_urls 获取xpath://video/@src|//video/@autoplay
# !/usr/bin/python3
# -*- coding:utf-8 -*-
"""
@author: JHC000abc@gmail.com
@file: demo1.py
@time: 2024/6/3 18:00
@desc:
"""
import os
import re
import requests
from urllib.parse import unquote
video_urls = """
//f.video.weibocdn.com/o0/zKaeA2tblx08gbCvECPu01041200IOoj0E010.mp4?label=mp4_720p&template=1280x720.25.0&media_id=5052810367008865&tp=8x8A3El:YTkl0eM8&us=0&ori=1&bf=4&ot=h&lp=1627bfY897x0uXgBMWir7m&ps=mZ6WB&uid=7epJGb&ab=,3601-g29,3601-g36,8013-g0,3601-g29&Expires=1720171780&ssig=8qWxUtq8yo&KID=unistore,video
//f.video.weibocdn.com/u0/9wDNW1Vbgx08g6G0UMUw010412006JcC0E010.mp4?label=mp4_720p&template=1280x720.25.0&media_id=5051678257250342&tp=8x8A3El:YTkl0eM8&us=0&ori=1&bf=4&ot=h&lp=1627bfY897x0uXgBMWir7m&ps=mZ6WB&uid=7epJGb&ab=,8013-g0,3601-g29,3601-g19&Expires=1720171780&ssig=9M9pGiLdMH&KID=unistore,video
//f.video.weibocdn.com/o0/gt0Ytfoqlx08gaji3S0M01041200aSUW0E010.mp4?label=mp4_720p&template=720x1280.24.0&media_id=5052514500804658&tp=8x8A3El:YTkl0eM8&us=0&ori=1&bf=4&ot=v&lp=1627bfY897x0uXgBMWir7m&ps=mZ6WB&uid=7epJGb&ab=,3601-g19,3601-g36,8013-g0,3601-g19&Expires=1720171780&ssig=qwN8M8Cyc9&KID=unistore,video
//f.video.weibocdn.com/o0/zKaeA2tblx08gbCvECPu01041200IOoj0E010.mp4?label=mp4_720p&template=1280x720.25.0&media_id=5052810367008865&tp=8x8A3El:YTkl0eM8&us=0&ori=1&bf=4&ot=h&lp=1627bfY897x0uXgBMWir7m&ps=mZ6WB&uid=7epJGb&ab=,3601-g29,3601-g36,8013-g0,3601-g29&Expires=1720171780&ssig=8qWxUtq8yo&KID=unistore,video
//f.video.weibocdn.com/u0/9wDNW1Vbgx08g6G0UMUw010412006JcC0E010.mp4?label=mp4_720p&template=1280x720.25.0&media_id=5051678257250342&tp=8x8A3El:YTkl0eM8&us=0&ori=1&bf=4&ot=h&lp=1627bfY897x0uXgBMWir7m&ps=mZ6WB&uid=7epJGb&ab=,8013-g0,3601-g29,3601-g19&Expires=1720171780&ssig=9M9pGiLdMH&KID=unistore,video
//f.video.weibocdn.com/o0/6E1OuJczlx08ga4CWyUE010412004Kk00E010.mp4?label=mp4_720p&template=576x1024.24.0&media_id=5052461132480572&tp=8x8A3El:YTkl0eM8&us=0&ori=1&bf=4&ot=v&lp=1627bfY897x0uXgBMWir7m&ps=mZ6WB&uid=7epJGb&ab=,8013-g0,3601-g29,3601-g32,3601-g29&Expires=1720171780&ssig=LWQX1Q3kIo&KID=unistore,video
//f.video.weibocdn.com/o0/gt0Ytfoqlx08gaji3S0M01041200aSUW0E010.mp4?label=mp4_720p&template=720x1280.24.0&media_id=5052514500804658&tp=8x8A3El:YTkl0eM8&us=0&ori=1&bf=4&ot=v&lp=1627bfY897x0uXgBMWir7m&ps=mZ6WB&uid=7epJGb&ab=,3601-g19,3601-g36,8013-g0,3601-g19&Expires=1720171780&ssig=qwN8M8Cyc9&KID=unistore,video
//f.video.weibocdn.com/o0/LqQe1kzclx08gb0rhsQ001041200BOy30E010.mp4?label=mp4_720p&template=1280x720.25.0&media_id=5052670554079256&tp=8x8A3El:YTkl0eM8&us=0&ori=1&bf=4&ot=h&lp=1627bfY897x0uXgBMWir7m&ps=mZ6WB&uid=7epJGb&ab=,3601-g19,3601-g36,8013-g0,3601-g19&Expires=1720171780&ssig=GC11nHcWrX&KID=unistore,video
//f.video.weibocdn.com/o0/n9USvUA4lx08gb0R1LsQ01041200alO80E010.mp4?label=mp4_720p&template=1280x720.25.0&media_id=5052674530541583&tp=8x8A3El:YTkl0eM8&us=0&ori=1&bf=4&ot=h&lp=1627bfY897x0uXgBMWir7m&ps=mZ6WB&uid=7epJGb&ab=,8012-g2,8013-g0,3601-g29&Expires=1720171780&ssig=KOc88BIlZA&KID=unistore,video
//f.video.weibocdn.com/o0/6E1OuJczlx08ga4CWyUE010412004Kk00E010.mp4?label=mp4_720p&template=576x1024.24.0&media_id=5052461132480572&tp=8x8A3El:YTkl0eM8&us=0&ori=1&bf=4&ot=v&lp=1627bfY897x0uXgBMWir7m&ps=mZ6WB&uid=7epJGb&ab=,8013-g0,3601-g29,3601-g32,3601-g29&Expires=1720171780&ssig=LWQX1Q3kIo&KID=unistore,video
//f.video.weibocdn.com/o0/gt0Ytfoqlx08gaji3S0M01041200aSUW0E010.mp4?label=mp4_720p&template=720x1280.24.0&media_id=5052514500804658&tp=8x8A3El:YTkl0eM8&us=0&ori=1&bf=4&ot=v&lp=1627bfY897x0uXgBMWir7m&ps=mZ6WB&uid=7epJGb&ab=,3601-g19,3601-g36,8013-g0,3601-g19&Expires=1720171780&ssig=qwN8M8Cyc9&KID=unistore,video
//f.video.weibocdn.com/o0/LqQe1kzclx08gb0rhsQ001041200BOy30E010.mp4?label=mp4_720p&template=1280x720.25.0&media_id=5052670554079256&tp=8x8A3El:YTkl0eM8&us=0&ori=1&bf=4&ot=h&lp=1627bfY897x0uXgBMWir7m&ps=mZ6WB&uid=7epJGb&ab=,3601-g19,3601-g36,8013-g0,3601-g19&Expires=1720171780&ssig=GC11nHcWrX&KID=unistore,video
//f.video.weibocdn.com/o0/zJuWIWXKlx08ga81eflK010412003zdR0E010.mp4?label=mp4_720p&template=576x1024.24.0&media_id=5052473094897696&tp=8x8A3El:YTkl0eM8&us=0&ori=1&bf=4&ot=v&lp=1627bfY897x0uXgBMWir7m&ps=mZ6WB&uid=7epJGb&ab=,3601-g29,3601-g36,8013-g0,3601-g29&Expires=1720171780&ssig=cjLfJlLX%2Fw&KID=unistore,video
//f.video.weibocdn.com/o0/n9USvUA4lx08gb0R1LsQ01041200alO80E010.mp4?label=mp4_720p&template=1280x720.25.0&media_id=5052674530541583&tp=8x8A3El:YTkl0eM8&us=0&ori=1&bf=4&ot=h&lp=1627bfY897x0uXgBMWir7m&ps=mZ6WB&uid=7epJGb&ab=,8012-g2,8013-g0,3601-g29&Expires=1720171780&ssig=KOc88BIlZA&KID=unistore,video
//f.video.weibocdn.com/o0/En7smZPNlx08gaAb2CSI01041200yNl60E010.mp4?label=mp4_720p&template=720x960.24.0&media_id=5052576412926010&tp=8x8A3El:YTkl0eM8&us=0&ori=1&bf=4&ot=v&lp=1627bfY897x0uXgBMWir7m&ps=mZ6WB&uid=7epJGb&ab=,8013-g0,3601-g29,3601-g32,3601-g29&Expires=1720171780&ssig=%2BGqaB%2FC28h&KID=unistore,video
//f.video.weibocdn.com/o0/g6473TnUlx08gaBgZYsw01041200hdZ90E010.mp4?label=mp4_720p&template=1280x720.25.0&media_id=5052580477468697&tp=8x8A3El:YTkl0eM8&us=0&ori=1&bf=4&ot=h&lp=1627bfY897x0uXgBMWir7m&ps=mZ6WB&uid=7epJGb&ab=,3601-g19,3601-g36,8013-g0,3601-g19&Expires=1720171780&ssig=37RdF2I2tI&KID=unistore,video
"""
for i in video_urls.split("\n"):
i = i.strip()
if i:
try:
host = re.findall("(.*?)/o0/", i)[0]
if host.startswith("//"):
host = f"https:{host}"
video_id = re.findall("/o0/(.*?).mp4", i)[0]
ssig = unquote(re.findall("ssig=(.*?)&", i)[0])
Expire = re.findall("Expires=(.*?)&", i)[0]
except:
pass
else:
print(video_id, ssig, Expire)
headers = {
"Referer": "https://weibo.com/",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36",
}
url = f"{host}/o0/{video_id}.mp4"
params = {
"Expires": f"{Expire}",
"ssig": f"{ssig}",
"KID": "unistore,video"
}
response = requests.get(url, headers=headers, params=params)
# print(response.text)
print(response)
os.makedirs("videos", exist_ok=True)
with open(f"videos/{video_id}.mp4", "wb") as fp:
fp.write(response.content)