diff --git a/projects/download GeeksForGeeks articles/downloader.py b/projects/download GeeksForGeeks articles/downloader.py new file mode 100644 index 000000000..7742edca9 --- /dev/null +++ b/projects/download GeeksForGeeks articles/downloader.py @@ -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") diff --git a/projects/download GeeksForGeeks articles/readme.md b/projects/download GeeksForGeeks articles/readme.md new file mode 100644 index 000000000..924ab5295 --- /dev/null +++ b/projects/download GeeksForGeeks articles/readme.md @@ -0,0 +1,23 @@ +# Download GeeksForGeeks Articles as pdf + +This script take a link of GeeksForGeeks article as input and download the complete article as a pdf at default download location. + +### Prerequisites + +* selenium +* requests +* webdriver-manager +* Run `pip install -r requirements.txt` to install required external modules. + +### How to run the script + +- Execute `python3 downloader.py` +- Type in URL of article when prompted. + +### Screenshot/GIF showing the sample use of the script + +![Screenshot of the Output](Screenshot.jpg) + +## *Author Name* + +[Shiv Thakur](https://github.com/ShivSt) \ No newline at end of file diff --git a/projects/download GeeksForGeeks articles/requirements.txt b/projects/download GeeksForGeeks articles/requirements.txt new file mode 100644 index 000000000..a65ab54dc --- /dev/null +++ b/projects/download GeeksForGeeks articles/requirements.txt @@ -0,0 +1,3 @@ +requests==2.24.0 +selenium==3.141.0 +webdriver-manager==3.2.2 \ No newline at end of file diff --git a/projects/download GeeksForGeeks articles/screenshot.jpg b/projects/download GeeksForGeeks articles/screenshot.jpg new file mode 100644 index 000000000..a8fce8eda Binary files /dev/null and b/projects/download GeeksForGeeks articles/screenshot.jpg differ