PDF文件将不会下载

发布于 2025-02-03 11:39:42 字数 407 浏览 3 评论 0原文

由于某种原因,我无法下载它,并且内容类型为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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陈甜 2025-02-10 11:39:42

尝试更改用户代理

import requests

r = requests.get(
    "https://cases.stretto.com/public/X070/10255/PLEADINGS/1025505242280000000049.pdf",
    allow_redirects=True,
    headers={
        "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:100.0) Gecko/20100101 Firefox/100.0"
    },
)

with open("1.pdf", "wb") as f_out:
    f_out.write(r.content)

保存1.pdf

andrej@andrej:~$ ls -alF 1.pdf
-rw-r--r-- 1 root root 243976 máj 30 23:03 1.pdf

Try to change User-Agent:

import requests

r = requests.get(
    "https://cases.stretto.com/public/X070/10255/PLEADINGS/1025505242280000000049.pdf",
    allow_redirects=True,
    headers={
        "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:100.0) Gecko/20100101 Firefox/100.0"
    },
)

with open("1.pdf", "wb") as f_out:
    f_out.write(r.content)

Saves 1.pdf:

andrej@andrej:~$ ls -alF 1.pdf
-rw-r--r-- 1 root root 243976 máj 30 23:03 1.pdf
最美的太阳 2025-02-10 11:39:42

Andrej具有上面的正确答案,但是如果您想要一个OS行: -

curl -A "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:100.0) Gecko/20100101 Firefox/100.0" -O https://cases.stretto.com/public/X070/10255/PLEADINGS/1025505242280000000049.pdf

结果

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  238k  100  238k    0     0   295k      0 --:--:-- --:--:-- --:--:--  295k

>1025505242280000000049.pdf

”在此处输入图像说明”

Andrej has the correct answer above but if you want a single OS line:-

curl -A "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:100.0) Gecko/20100101 Firefox/100.0" -O https://cases.stretto.com/public/X070/10255/PLEADINGS/1025505242280000000049.pdf

result

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  238k  100  238k    0     0   295k      0 --:--:-- --:--:-- --:--:--  295k

>1025505242280000000049.pdf

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文