# 设置请求头,模拟浏览器访问 headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" }
defdownload_file(file_url, file_path): """下载文件并保存到指定路径""" print() try: with requests.get(file_url, stream=True, headers=headers) as r: r.raise_for_status() withopen(file_path, 'wb') as f: for chunk in r.iter_content(chunk_size=8192): f.write(chunk) print(f"Downloaded: {file_url} -> {file_path}") except Exception as e: print(f"Failed to download {file_url}: {e}")