Skip to content
This repository was archived by the owner on May 25, 2022. It is now read-only.
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
54 changes: 54 additions & 0 deletions projects/download GeeksForGeeks articles/downloader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# !/usr/bin/env python
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
import json
import requests


# article url
# URL = "https://www.geeksforgeeks.org/what-can-i-do-with-python/"


def get_driver():
# chrome options settings
chrome_options = webdriver.ChromeOptions()
settings = {
"recentDestinations": [
{"id": "Save as PDF", "origin": "local", "account": ""}
],
"selectedDestinationId": "Save as PDF",
"version": 2,
}
prefs = {
"printing.print_preview_sticky_settings.appState": json.dumps(settings)
}
chrome_options.add_experimental_option("prefs", prefs)
chrome_options.add_argument("--kiosk-printing")

# launch browser with predefined settings
browser = webdriver.Chrome(
executable_path=ChromeDriverManager().install(), options=chrome_options
)
return browser


def download_article(URL):
browser = get_driver()
browser.get(URL)

# launch print and save as pdf
browser.execute_script("window.print();")
browser.close()


if __name__ == "__main__":
URL = input("provide article URL: ")
# check if the url is valid/reachable
if requests.get(URL).status_code == 200:
try:
download_article(URL)
print("Your article is successfully downloaded")
except Exception as e:
print(e)
else:
print("Enter a valid working URL")
23 changes: 23 additions & 0 deletions projects/download GeeksForGeeks articles/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Download GeeksForGeeks Articles as pdf
<!--Remove the below lines and add yours -->
This script take a link of GeeksForGeeks article as input and download the complete article as a pdf at default download location.

### Prerequisites
<!--Remove the below lines and add yours -->
* selenium
* requests
* webdriver-manager
* Run `pip install -r requirements.txt` to install required external modules.

### How to run the script
<!--Remove the below lines and add yours -->
- Execute `python3 downloader.py`
- Type in URL of article when prompted.

### Screenshot/GIF showing the sample use of the script
<!--Remove the below lines and add yours -->
![Screenshot of the Output](Screenshot.jpg)

## *Author Name*
<!--Remove the below lines and add yours -->
[Shiv Thakur](https://github.com/ShivSt)
3 changes: 3 additions & 0 deletions projects/download GeeksForGeeks articles/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
requests==2.24.0
selenium==3.141.0
webdriver-manager==3.2.2
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.