PDF文件将不会下载
由于某种原因,我无法下载它,并且内容类型为HTML \ Text,而不是PDF。下载的PDF文件总是很小,当我尝试打开它时,文件已损坏。
import request
docketnumber='1'
r = requests.get('https://cases.stretto.com/public/X070/10255/PLEADINGS/1025505242280000000049.pdf', allow_redirects=True, headers={'User-Agent': 'Mozilla/5.0'})
print(r.headers.get('content-type'))
open('C:/MyDownloads/' + docketnumber+".pdf", 'wb' ).write(r.content)```
For some reason I can't get this to download and the content type is html\text and not pdf. The downloaded pdf file is always very small and when I try to open it the file is corrupted.
import request
docketnumber='1'
r = requests.get('https://cases.stretto.com/public/X070/10255/PLEADINGS/1025505242280000000049.pdf', allow_redirects=True, headers={'User-Agent': 'Mozilla/5.0'})
print(r.headers.get('content-type'))
open('C:/MyDownloads/' + docketnumber+".pdf", 'wb' ).write(r.content)```
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试更改
用户代理
:保存
1.pdf
:Try to change
User-Agent
:Saves
1.pdf
:Andrej具有上面的正确答案,但是如果您想要一个OS行: -
结果
Andrej has the correct answer above but if you want a single OS line:-
result