Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on May 25, 2022. It is now read-only.

Commit 05fad88

Browse files
committed
Script added for saving GeeksforGeeks article as pdf #229
1 parent 53950a3 commit 05fad88

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# !/usr/bin/env python
2+
from selenium import webdriver
3+
import json
4+
import requests
5+
6+
7+
# article url
8+
# URL = "https://www.geeksforgeeks.org/what-can-i-do-with-python/"
9+
10+
11+
def download_article(URL):
12+
# chrome options settings
13+
chrome_options = webdriver.ChromeOptions()
14+
settings = {
15+
"recentDestinations": [
16+
{"id": "Save as PDF", "origin": "local", "account": ""}
17+
],
18+
"selectedDestinationId": "Save as PDF",
19+
"version": 2,
20+
}
21+
prefs = {
22+
"printing.print_preview_sticky_settings.appState": json.dumps(settings)
23+
}
24+
chrome_options.add_experimental_option("prefs", prefs)
25+
chrome_options.add_argument("--kiosk-printing")
26+
chrome_options.binary_location = (
27+
r"C:\Program Files (x86)/"
28+
+ r"BraveSoftware\Brave-Browser\Application\brave.exe"
29+
)
30+
CHROMEDRIVER_PATH = r"chromedriver.exe"
31+
32+
# launch browser with predefined settings
33+
browser = webdriver.Chrome(
34+
executable_path=CHROMEDRIVER_PATH, options=chrome_options
35+
)
36+
browser.get(URL)
37+
38+
# launch print and save as pdf
39+
browser.execute_script("window.print();")
40+
browser.close()
41+
42+
43+
if __name__ == "__main__":
44+
URL = input("provide article URL: ")
45+
if requests.get(URL).status_code == 200:
46+
download_article(URL)
47+
print("Your article is successfully downloaded")
48+
else:
49+
print("Enter a valid working URL")
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Download GeeksForGeeks Articles as pdf
2+
<!--Remove the below lines and add yours -->
3+
This script take the link to a GeeksForGeeks article as input and store the complete article as a pdf.
4+
5+
### Prerequisites
6+
<!--Remove the below lines and add yours -->
7+
* selenium
8+
* requests
9+
* Run `pip install -r requirements.txt` to install required external modules.
10+
11+
### How to run the script
12+
<!--Remove the below lines and add yours -->
13+
- Execute `python3 downloader.py`
14+
- Type in URL of article when prompted.
15+
16+
### Screenshot/GIF showing the sample use of the script
17+
<!--Remove the below lines and add yours -->
18+
![Screenshot of the Output](Screenshot.jpg)
19+
20+
## *Author Name*
21+
<!--Remove the below lines and add yours -->
22+
[Shiv Thakur](https://github.com/ShivSt)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
requests==2.24.0
2+
selenium==3.141.0
45.1 KB
Loading[フレーム]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /