Skip to content

Commit f815c8a

Browse files
committed
removed static location requirements
1 parent 05fad88 commit f815c8a

3 files changed

Lines changed: 17 additions & 10 deletions

File tree

‎projects/download GeeksForGeeks articles/downloader.py‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# !/usr/bin/env python
22
from selenium import webdriver
3+
from webdriver_manager.chrome import ChromeDriverManager
34
import json
45
import requests
56

@@ -8,7 +9,7 @@
89
# URL = "https://www.geeksforgeeks.org/what-can-i-do-with-python/"
910

1011

11-
def download_article(URL):
12+
def get_driver():
1213
# chrome options settings
1314
chrome_options = webdriver.ChromeOptions()
1415
settings = {
@@ -23,16 +24,16 @@ def download_article(URL):
2324
}
2425
chrome_options.add_experimental_option("prefs", prefs)
2526
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"
3127

3228
# launch browser with predefined settings
3329
browser = webdriver.Chrome(
34-
executable_path=CHROMEDRIVER_PATH, options=chrome_options
30+
executable_path=ChromeDriverManager().install(), options=chrome_options
3531
)
32+
return browser
33+
34+
35+
def download_article(URL):
36+
browser = get_driver()
3637
browser.get(URL)
3738

3839
# launch print and save as pdf
@@ -42,8 +43,12 @@ def download_article(URL):
4243

4344
if __name__ == "__main__":
4445
URL = input("provide article URL: ")
46+
# check if the url is valid/reachable
4547
if requests.get(URL).status_code == 200:
46-
download_article(URL)
47-
print("Your article is successfully downloaded")
48+
try:
49+
download_article(URL)
50+
print("Your article is successfully downloaded")
51+
except Exception as e:
52+
print(e)
4853
else:
4954
print("Enter a valid working URL")

‎projects/download GeeksForGeeks articles/readme.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# Download GeeksForGeeks Articles as pdf
22
<!--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.
3+
This script take a link of GeeksForGeeks article as input and download the complete article as a pdf at default download location.
44

55
### Prerequisites
66
<!--Remove the below lines and add yours -->
77
* selenium
88
* requests
9+
* webdriver-manager
910
* Run `pip install -r requirements.txt` to install required external modules.
1011

1112
### How to run the script
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
requests==2.24.0
22
selenium==3.141.0
3+
webdriver-manager==3.2.2

0 commit comments

Comments
 (0)