File tree Expand file tree Collapse file tree
projects/download GeeksForGeeks articles Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # !/usr/bin/env python
2+ from selenium import webdriver
3+ from webdriver_manager .chrome import ChromeDriverManager
4+ import json
5+ import requests
6+
7+
8+ # article url
9+ # URL = "https://www.geeksforgeeks.org/what-can-i-do-with-python/"
10+
11+
12+ def get_driver ():
13+ # chrome options settings
14+ chrome_options = webdriver .ChromeOptions ()
15+ settings = {
16+ "recentDestinations" : [
17+ {"id" : "Save as PDF" , "origin" : "local" , "account" : "" }
18+ ],
19+ "selectedDestinationId" : "Save as PDF" ,
20+ "version" : 2 ,
21+ }
22+ prefs = {
23+ "printing.print_preview_sticky_settings.appState" : json .dumps (settings )
24+ }
25+ chrome_options .add_experimental_option ("prefs" , prefs )
26+ chrome_options .add_argument ("--kiosk-printing" )
27+
28+ # launch browser with predefined settings
29+ browser = webdriver .Chrome (
30+ executable_path = ChromeDriverManager ().install (), options = chrome_options
31+ )
32+ return browser
33+
34+
35+ def download_article (URL ):
36+ browser = get_driver ()
37+ browser .get (URL )
38+
39+ # launch print and save as pdf
40+ browser .execute_script ("window.print();" )
41+ browser .close ()
42+
43+
44+ if __name__ == "__main__" :
45+ URL = input ("provide article URL: " )
46+ # check if the url is valid/reachable
47+ if requests .get (URL ).status_code == 200 :
48+ try :
49+ download_article (URL )
50+ print ("Your article is successfully downloaded" )
51+ except Exception as e :
52+ print (e )
53+ else :
54+ print ("Enter a valid working URL" )
Original file line number Diff line number Diff line change 1+ # Download GeeksForGeeks Articles as pdf
2+ <!-- Remove the below lines and add yours -->
3+ This script take a link of GeeksForGeeks article as input and download the complete article as a pdf at default download location.
4+
5+ ### Prerequisites
6+ <!-- Remove the below lines and add yours -->
7+ * selenium
8+ * requests
9+ * webdriver-manager
10+ * Run ` pip install -r requirements.txt ` to install required external modules.
11+
12+ ### How to run the script
13+ <!-- Remove the below lines and add yours -->
14+ - Execute ` python3 downloader.py `
15+ - Type in URL of article when prompted.
16+
17+ ### Screenshot/GIF showing the sample use of the script
18+ <!-- Remove the below lines and add yours -->
19+ ![ Screenshot of the Output] ( Screenshot.jpg )
20+
21+ ## * Author Name*
22+ <!-- Remove the below lines and add yours -->
23+ [ Shiv Thakur] ( https://github.com/ShivSt )
Original file line number Diff line number Diff line change 1+ requests == 2.24.0
2+ selenium == 3.141.0
3+ webdriver-manager == 3.2.2
You can’t perform that action at this time.
0 commit comments