How to download PDF using Python

Photo by Nicolas Picard on Unsplash

Python is really cool language and most important I love the web scraping concept of python. so basically web scraping can be referred to as gathering information from sources such as websites and using it for project

I have written a program that downloads a pdf from a specified link for example I have to use a dummy site that does not really exist to download a pdf

import socket

import requests

url= “http://xyz.com/sample.pdf"

res = requests.get(url)

print(res)

f = open(“sample.pdf”,”wb”)

f.write(res.content)

f.close()

In this example, it copies all content of the pdf file to a new file called smaple.pdf and stores it in the current directory.if pdf is not on site it will show error 404 i.e file not found

response error 404

I would like to share more experiments that I have done with web scraping

--

--

--

Engineering student who loves coding

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Reduce Cost and Increase Productivity with Value Added IT Services from buzinessware — {link} -

Java JDBC Driver

10 Tips That Will Make You A Better Developer

Ruby Conditional Statements

Customizing ModelMultipleChoiceField in a Django Form

Physical computing

Echo 101: Timeout middleware in Echo framework

Why I rebuilt Basecamp’s website … with no result

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Shashankk

Shashankk

Engineering student who loves coding

More from Medium

Tkinter: python’s standard GUI

Making Notepad GUI using Tkinter and Python

Flask Blueprints, Error Handling, and Config File Example

Docker python image with psycopg2 installed