pdf文件不会下载
pdf file will not download
出于某种原因我无法下载它,内容类型是 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)```
尝试改变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)
节省 1.pdf
:
andrej@andrej:~$ ls -alF 1.pdf
-rw-r--r-- 1 root root 243976 máj 30 23:03 1.pdf
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
出于某种原因我无法下载它,内容类型是 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)```
尝试改变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)
节省 1.pdf
:
andrej@andrej:~$ ls -alF 1.pdf
-rw-r--r-- 1 root root 243976 máj 30 23:03 1.pdf
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