情况说明
尝试利用_requests_库对已知URL的PDF文件进行下载,出现部分PDF文件打开失败的情况。
软件环境
python:3.8
requests:2.24
源代码:
import requests
url1 = 'https://buildmedia.readthedocs.org/media/pdf/python-guide/latest/python-guide.pdf'
# url2 = 'https://cyber.bban.top/MTAuMTAwNy9iZjAwMjY4MzU1/touati-schwartz1979.pdf'
# url1对应此PDF文件下载后可以打开
r = requests.get(url1, stream=True)
with open("G://Python project//first use of requests//DOI Download//test1.pdf", "wb") as Pypdf:
for chunk in r.iter_content(chunk_size=1024):
if chunk:
Pypdf.write(chunk)
print('done!')
# url2对应此PDF文件可以下载,但打开失败
"""
r = requests.get(url2, stream=True)
with open("G://Python project//first use of requests//DOI Download//test2.pdf", "wb") as Pypdf:
for chunk in r.iter_content(chunk_size=1024):
if chunk:
Pypdf.write(chunk)
print('done!')
"""
错误提示
url2文件下载后打开出现下图提示
烦请指教,不胜感激