import requests
session = requests.Session()
设置请求头
headers = {
“User-Agent”: “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0”,
“Referer”: “https://m.ddooo.com/softdown/12142.htm” # 这里建议将Referer设置为与下载链接相关的页面地址,比如最初提供下载链接所在的页面地址,示例中假设是这个地址,你可根据实际情况调整
}
在会话中发送请求
response = session.get(url=“https://soft-10-0.xiaoguaniu.com/soft/202203/PotPlayer_V220302_XiTongZhiJia.zip”, headers=headers)
print(response.status_code)
# 假设要保存的文件名
file_name = “PotPlayer.zip”
with open(file_name, “wb”) as file:
file.write(response.content)
print(“文件下载成功!”)