如果我打开链接: https://dibbs2.bsm.dla.mil/Downloads/RFQ/Archive/ca210731.zip此链接显示了窗口,我需要按 OK 按钮并下载文件。警报不是来自浏览器,而是来自页面本身。但是当我尝试脚本时:
from io import BytesIO from zipfile import ZipFile import requests def get_zip(file_url): url = requests.get(file_url) zipfile = ZipFile(BytesIO(url.content)) zipfile.extractall("") file_link ='https://dibbs2.bsm.dla.mil/Downloads/RFQ/Archive/ca210731.zip' get_zip(file_link)
这会引发错误:zipfile.BadZipFile: File is not a zip file当我尝试时:
import requests url = r'https://dibbs2.bsm.dla.mil/Downloads/RFQ/Archive/ca210731.zip' output = r'downloadedfile.zip' r = requests.get(url) with open(output, 'wb') as f: f.write(r.content)
这将下载显示 OK 按钮的页面内容。知道如何解决这个问题:链接下载 zip 文件。