|
15 | 15 |
|
16 | 16 | import browsers |
17 | 17 | import requests |
18 | | -from requests import Response, RequestException |
| 18 | +from requests import RequestException, Response |
19 | 19 | from selenium import webdriver |
20 | 20 | from selenium.webdriver.chrome.options import Options |
21 | 21 | from selenium.webdriver.chrome.service import Service |
|
41 | 41 |
|
42 | 42 | class ChromeDriverManager: |
43 | 43 | def get_chrome_driver(self, path_to_cache_dir: str): |
44 | | - chrome_version = self.get_chrome_version() |
| 44 | + chrome_browser_info = browsers.get("chrome") |
| 45 | + chrome_version = chrome_browser_info["version"] |
45 | 46 |
|
46 | 47 | # If Web Driver Manager cannot detect Chrome, it returns None. |
47 | 48 | if chrome_version is None: |
@@ -181,8 +182,9 @@ def send_http_get_request(url, params=None, **kwargs) -> Response: |
181 | 182 | f"html2print: " |
182 | 183 | f"failed to get response for URL: {url} with error: {last_error}" |
183 | 184 | ) |
184 | | - raise RequestException(f"GET request failed after 3 attempts: {url}") from last_error |
185 | | - |
| 185 | + raise RequestException( |
| 186 | + f"html2print: GET request failed after 3 attempts: {url}" |
| 187 | + ) from last_error |
186 | 188 |
|
187 | 189 | @staticmethod |
188 | 190 | def get_chrome_version(): |
@@ -329,7 +331,12 @@ def create_webdriver( |
329 | 331 | else: |
330 | 332 | service = Service(path_to_chrome) |
331 | 333 |
|
| 334 | + path_to_chrome_browser = "" |
| 335 | + path_to_chrome_browser = browsers.get("chrome")["path"] |
| 336 | + print(f"html2print: Chrome available at path: {path_to_chrome_browser}") # noqa: T201 |
| 337 | + |
332 | 338 | webdriver_options = Options() |
| 339 | + webdriver_options.binary_location = path_to_chrome_browser |
333 | 340 | webdriver_options.add_argument("start-maximized") |
334 | 341 | webdriver_options.add_argument("disable-infobars") |
335 | 342 | # Doesn't seem to be needed. |
@@ -462,7 +469,7 @@ def main(): |
462 | 469 | if browsers.get("chrome") is not None: |
463 | 470 | path_to_chrome_browser = browsers.get("chrome")["path"] |
464 | 471 | print( # noqa: T201 |
465 | | - f"html2print: Chrome available at path:{path_to_chrome_browser}" |
| 472 | + f"html2print: Chrome available at path: {path_to_chrome_browser}" |
466 | 473 | ) |
467 | 474 | sys.exit(0) |
468 | 475 |
|
|
0 commit comments