Skip to content
This repository was archived by the owner on Mar 25, 2024. It is now read-only.

Commit f4cdea1

Browse files
committedMay 21, 2022
Update webdrivers to support latest version
1 parent 891f4ac commit f4cdea1

7 files changed

+45
-29
lines changed
 

‎.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
emails.txt
33
geckodriver.log
44
lib/__pycache__/
5-
venv
5+
venv*
66
*test*

‎drivers/chromedriver

156 KB
Binary file not shown.

‎drivers/chromedriver.exe

646 KB
Binary file not shown.

‎drivers/geckodriver

265 KB
Binary file not shown.

‎drivers/geckodriver.exe

244 KB
Binary file not shown.

‎lib/selenium_wrapper.py

+40-24
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,53 @@
22
from selenium.webdriver.chrome.options import Options as ChromeOptions
33
from selenium.webdriver.firefox.options import Options as FirefoxOptions
44
from sys import platform
5+
from pathlib import Path
56

7+
ERROR_MSG_BASE = (
8+
"Scrapping only the name and the number of contributions "
9+
"from Google Maps public profile"
10+
)
611

712
class SeleniumWrapper:
13+
814
def __init__(self, browser):
9-
self.browser = browser
15+
# TODO check browser validity
16+
self.browser = browser[0].upper() + browser[1:]
17+
1018
self.driver = None
11-
DRIVER_PATH = ""
19+
self._set_driver()
20+
1221

13-
# Detect OS
22+
def _get_driver_extension(self):
1423
if platform.startswith("linux"):
15-
EXT = ""
24+
return ""
1625
elif platform.startswith("win32"):
17-
EXT = ".exe"
18-
else:
19-
raise Exception(
20-
"The use of selenium is not supported for this OS. "
21-
'Only "linux" and "win32" are possible\n',
22-
"Scrapping only the name and the number of contributions "
23-
"from Google Maps public profile",
24-
sep="\n",
25-
)
26-
27-
# Choose the good driver
28-
if self.browser == "chrome":
29-
options = ChromeOptions()
30-
DRIVER_PATH = f"./drivers/chromedriver{EXT}"
31-
self.driver = webdriver.Chrome(options=options, executable_path=DRIVER_PATH)
26+
return ".exe"
27+
raise Exception(
28+
"Mailfogle with selenium is not supported for this OS. "
29+
'Only "linux" and "windows" are possible\n' + ERROR_MSG_BASE
30+
)
31+
32+
def _set_driver(self):
33+
msg = (
34+
"Your {browser} profile cannot be loaded. "
35+
"It may be missing or inaccessible.\n" + ERROR_MSG_BASE
36+
)
3237

33-
elif self.browser == "firefox":
38+
extension = self._get_driver_extension()
39+
40+
if self.browser == "Chrome":
41+
options = ChromeOptions()
42+
driver_filename = "chromedriver" + extension
43+
elif self.browser == "Firefox":
3444
options = FirefoxOptions()
35-
DRIVER_PATH = f"./drivers/geckodriver{EXT}"
36-
self.driver = webdriver.Firefox(
37-
options=options, executable_path=DRIVER_PATH
38-
)
45+
driver_filename = "geckodriver" + extension
46+
47+
driver_path = f"./drivers/{driver_filename}"
48+
if not Path(driver_path).is_file():
49+
raise Exception(msg.format(browser=self.browser))
50+
51+
52+
self.driver = getattr(webdriver, self.browser)(
53+
options=options, executable_path=driver_path
54+
)

‎requirements.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
beautifulsoup4==4.9.3
2-
google-api-python-client==2.6.0
3-
google-auth-oauthlib==0.4.4
4-
selenium==3.141.0
1+
beautifulsoup4>=4.9.3
2+
google-api-python-client>=2.6.0
3+
google-auth-oauthlib>=0.4.4
4+
selenium>=3.141.0

0 commit comments

Comments
 (0)
This repository has been archived.