AzerSD
AzerSD

Reputation: 168

Python - Scraping a PDF file from a URL

I want to scrape pdf files from this site https://www.sigmaths.net/Reader.php?var=manuels/ph/physique_pilote_7b.pdf I tried this code for that but it doesn't work. Can anybody tell me why, please?

res = requests.get('https://www.sigmaths.net/Reader.php?var=manuels/ph/physique_7b.pdf')
with open('C:\\Users\\sioud\\Desktop\\Manuels scolaires TN\\1\\test.pdf', 'wb') as f:
f.write(ress.content)

Upvotes: 0

Views: 202

Answers (2)

Steffi Keran Rani J
Steffi Keran Rani J

Reputation: 4113

You can also use urlretrieve. Check out my solution code.

from urllib.request import urlretrieve
pdfurl = u"https://www.sigmaths.net/manuels/ph/physique_7b.pdf";
urlretrieve(pdfurl, "test.pdf")

And you will find the required pdf download under the name test.pdf

Upvotes: 0

Ajay
Ajay

Reputation: 5347

res = requests.get('https://www.sigmaths.net/manuels/ph/physique_7b.pdf',stream=True)
with open('test.pdf', 'wb') as f:
    f.write(res.content)

your url is pointing to a reader https://www.sigmaths.net/Reader.php?var=manuels/ph/physique_7b.pdf, remove the 'reader.php?var= for the actual pdf

Upvotes: 1

Related Questions