Skip to content

Created a PDF_Downloader using Python Web Scraping #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions PDF_Downloader/Readme.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
This is the readme file of this project.
It's a basic PDF downloader from a certain link.


Install required dependancies

python -m pip install ./requirements.txt

How to run :

python pdf.py
19 changes: 19 additions & 0 deletions PDF_Downloader/pdf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os
import requests
from urllib.parse import urljoin
from bs4 import BeautifulSoup

#Put the link from which you need to download all the pdf
url = ""

#If there is no such folder, the script will create one automatically
folder_location = r'./NewFolder'
if not os.path.exists(folder_location):os.mkdir(folder_location)

response = requests.get(url)
soup= BeautifulSoup(response.text, "html.parser")
for link in soup.select("a[href$='.pdf']"):
#Name the pdf files using the last portion of each link which are unique in this case
filename = os.path.join(folder_location,link['href'].split('/')[-1])
with open(filename, 'wb') as f:
f.write(requests.get(urljoin(url,link['href'])).content)
2 changes: 2 additions & 0 deletions PDF_Downloader/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
beautifulsoup4==4.10.0
requests==2.18.4
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,4 @@ The contribution guidelines are as per the guide [HERE](https://github.com/larym
| 49 | [Pomodoro App](https://github.com/HarshitRV/Python-project-Scripts/tree/main/Pomodoro-App) | [HarshitRV](https://github.com/HarshitRV)
| 49 | [BullsAndCows](https://github.com/HarshitRV/Python-project-Scripts/tree/main/BullsAndCows) | [JerryChen](https://github.com/jerrychen1990)
| 50 | [Minesweeper AI](https://github.com/nrp114/Minsweeper_AI) | [Nisarg Patel](https://github.com/nrp114)
| 51 | [PDF Downloader](https://github.com/Sdccoding/Python-project-Scripts/tree/main/PDF_Downloader) | [Souhardya Das Chowdhury](https://github.com/Sdccoding)