Skip to content

Commit 31618d5

Browse files
committed
attempt to make chromedriver executable
1 parent d40a500 commit 31618d5

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/souperscraper/getchromedriver.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import argparse
44
from time import sleep
55
from pathlib import Path
6+
from os import access, X_OK
67
from typing import Optional
78

89
DEFAULT_PATH = Path.home() / ".chromedriver"
@@ -115,6 +116,19 @@ def download_chromedriver(filename: str, download_url: str, destdir: Optional[Pa
115116
return executable_path
116117

117118

119+
def try_make_executable(executable_path: Path):
120+
"""
121+
Try to make the chromedriver executable. Return True if successful, False otherwise.
122+
"""
123+
try:
124+
print(f"Making {executable_path} executable...")
125+
executable_path.chmod(executable_path.stat().st_mode | X_OK)
126+
except Exception as e:
127+
print(f"Failed to make {executable_path} executable. Error: {e}")
128+
129+
return access(executable_path, X_OK)
130+
131+
118132
def get_chromedriver() -> Optional[Path]:
119133
parser = argparse.ArgumentParser()
120134
parser.add_argument("-v", "--version", type=int, help="Chromedriver version number")
@@ -136,6 +150,19 @@ def get_chromedriver() -> Optional[Path]:
136150
return None
137151

138152
print("Success. Chromedriver executable downloaded and saved to:\n", executable_path)
153+
154+
if not try_make_executable(executable_path):
155+
print("Failed to make chromedriver executable. You may need to do this manually.")
156+
print("To make the chromedriver executable, run the following command:")
157+
print(f"chmod +x {executable_path}")
158+
else:
159+
print("Chromedriver is now executable.")
160+
161+
print("\nYou can now use the chromedriver with SouperScraper. For example:")
162+
print("from souperscraper import SouperScraper")
163+
print(f'scraper = SouperScraper("{executable_path!s}")')
164+
print("scraper.goto('https://example.com')")
165+
print("header = scraper.soup.find('h1').text")
139166
return executable_path
140167

141168

0 commit comments

Comments
 (0)