Spaces:
No application file
No application file
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,6 +19,8 @@ from selenium.webdriver.support.ui import WebDriverWait
|
|
| 19 |
from selenium.webdriver.support import expected_conditions as EC
|
| 20 |
from selenium.webdriver.chrome.options import Options
|
| 21 |
from selenium.common.exceptions import TimeoutException, NoSuchElementException
|
|
|
|
|
|
|
| 22 |
from PIL import Image
|
| 23 |
import io
|
| 24 |
|
|
@@ -102,9 +104,27 @@ def create_chrome_driver() -> webdriver.Chrome:
|
|
| 102 |
chrome_options.add_argument("--disable-extensions")
|
| 103 |
chrome_options.add_argument("--disable-plugins")
|
| 104 |
chrome_options.add_argument("--disable-images")
|
| 105 |
-
chrome_options.add_argument("--
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
-
driver = webdriver.Chrome(options=chrome_options)
|
| 108 |
driver.set_page_load_timeout(30)
|
| 109 |
driver.implicitly_wait(10)
|
| 110 |
|
|
|
|
| 19 |
from selenium.webdriver.support import expected_conditions as EC
|
| 20 |
from selenium.webdriver.chrome.options import Options
|
| 21 |
from selenium.common.exceptions import TimeoutException, NoSuchElementException
|
| 22 |
+
from webdriver_manager.chrome import ChromeDriverManager
|
| 23 |
+
from selenium.webdriver.chrome.service import Service
|
| 24 |
from PIL import Image
|
| 25 |
import io
|
| 26 |
|
|
|
|
| 104 |
chrome_options.add_argument("--disable-extensions")
|
| 105 |
chrome_options.add_argument("--disable-plugins")
|
| 106 |
chrome_options.add_argument("--disable-images")
|
| 107 |
+
chrome_options.add_argument("--remote-debugging-port=9222")
|
| 108 |
+
chrome_options.add_argument("--disable-web-security")
|
| 109 |
+
chrome_options.add_argument("--allow-running-insecure-content")
|
| 110 |
+
|
| 111 |
+
# Try multiple methods to get the right ChromeDriver
|
| 112 |
+
try:
|
| 113 |
+
# Method 1: Use webdriver-manager to auto-download matching version
|
| 114 |
+
service = Service(ChromeDriverManager().install())
|
| 115 |
+
driver = webdriver.Chrome(service=service, options=chrome_options)
|
| 116 |
+
except Exception as e1:
|
| 117 |
+
try:
|
| 118 |
+
# Method 2: Use system ChromeDriver if available
|
| 119 |
+
driver = webdriver.Chrome(options=chrome_options)
|
| 120 |
+
except Exception as e2:
|
| 121 |
+
# Method 3: Try with explicit path
|
| 122 |
+
try:
|
| 123 |
+
service = Service("/usr/local/bin/chromedriver")
|
| 124 |
+
driver = webdriver.Chrome(service=service, options=chrome_options)
|
| 125 |
+
except Exception as e3:
|
| 126 |
+
raise Exception(f"Failed to create Chrome driver. Tried multiple methods: {str(e1)}, {str(e2)}, {str(e3)}")
|
| 127 |
|
|
|
|
| 128 |
driver.set_page_load_timeout(30)
|
| 129 |
driver.implicitly_wait(10)
|
| 130 |
|