直接上代码,抓包分析了半天,走了不少弯路,果然 朴实无华 才是最优解
python
# -*- coding: utf-8 -*-
# author: da_pangzi
# datetime: 2024/12/11 16:50
# ide: PyCharm
import requests
headers = {
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"accept-language": "zh-CN,zh;q=0.9",
"cache-control": "no-cache",
"pragma": "no-cache",
"priority": "u=0, i",
"sec-ch-ua": "\"Google Chrome\";v=\"129\", \"Not=A?Brand\";v=\"8\", \"Chromium\";v=\"129\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"sec-fetch-dest": "document",
"sec-fetch-mode": "navigate",
"sec-fetch-site": "none",
"sec-fetch-user": "?1",
"upgrade-insecure-requests": "1",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"
}
url = 'https://www.xiaohongshu.com/explore/6736be40000000001b012bf8?xsec_token=ABc_-Jlz_TFVL_yoP0s-gPQi3EYGGrt24dSY2XRfBRkEk=&xsec_source=pc_feed'
response = requests.get(url, headers=headers)
print(response.text)
print(response)
下载到本地的
python
# -*- coding: utf-8 -*-
# author: da_pangzi
# datetime: 2024/12/11 16:52
# ide: PyCharm
import requests
url = "https://sns-video-al.xhscdn.com/stream/110/258/01e736be401b382d01037001932dd76d83_258.mp4"
response = requests.get(url, stream=True)
with open("video.mp4", "wb") as f:
f.write(response.content)