42Cummer commited on
Commit
12852e9
·
verified ·
1 Parent(s): 13a9890
Files changed (2) hide show
  1. Dockerfile +9 -0
  2. app.py +3 -35
Dockerfile CHANGED
@@ -13,6 +13,15 @@ RUN apt-get update && apt-get install -y \
13
  && apt-get clean \
14
  && rm -rf /var/lib/apt/lists/*
15
 
 
 
 
 
 
 
 
 
 
16
  WORKDIR /app
17
 
18
  COPY requirements.txt requirements.txt
 
13
  && apt-get clean \
14
  && rm -rf /var/lib/apt/lists/*
15
 
16
+ # Install ChromeDriver
17
+ RUN CHROME_VERSION=$(google-chrome --version | grep -oE "[0-9]+\.[0-9]+\.[0-9]+") \
18
+ && wget -q "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${CHROME_VERSION%.*}" -O - \
19
+ && CHROMEDRIVER_VERSION=$(wget -q "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${CHROME_VERSION%.*}" -O -) \
20
+ && wget -q "https://chromedriver.storage.googleapis.com/${CHROMEDRIVER_VERSION}/chromedriver_linux64.zip" -O /tmp/chromedriver.zip \
21
+ && unzip /tmp/chromedriver.zip -d /usr/local/bin/ \
22
+ && rm /tmp/chromedriver.zip \
23
+ && chmod +x /usr/local/bin/chromedriver
24
+
25
  WORKDIR /app
26
 
27
  COPY requirements.txt requirements.txt
app.py CHANGED
@@ -16,10 +16,6 @@ import pytz
16
  from webdriver_manager.chrome import ChromeDriverManager
17
 
18
  os.environ["SE_CACHE_PATH"] = "/tmp/selenium"
19
- os.environ["WDM_LOCAL"] = "1"
20
- os.environ["WDM_CACHE_PATH"] = "/tmp/webdriver-manager"
21
- os.environ["WDM_LOG_LEVEL"] = "0"
22
- os.environ["WDM_SSL_VERIFY"] = "0"
23
 
24
  app = Flask(__name__)
25
  CORS(app)
@@ -270,37 +266,9 @@ def seek():
270
  options.add_argument("--disable-dev-shm-usage")
271
  options.add_argument("--remote-debugging-port=9222")
272
 
273
- # Try to use Chrome directly without webdriver-manager
274
- try:
275
- # First try direct Chrome path
276
- driver = webdriver.Chrome(options=options)
277
- except:
278
- try:
279
- # Fallback to webdriver-manager with forced path
280
- from webdriver_manager.core.os_manager import ChromeType
281
- from webdriver_manager.chrome import ChromeDriverManager
282
-
283
- # Force the cache path by monkey patching the default path
284
- import webdriver_manager.core.download_manager
285
- webdriver_manager.core.download_manager.DEFAULT_PATH = "/tmp/webdriver-manager"
286
-
287
- service = Service(ChromeDriverManager().install())
288
- driver = webdriver.Chrome(service=service, options=options)
289
- except Exception as e:
290
- print(f"ChromeDriver setup failed: {e}")
291
- # Last resort: try to find ChromeDriver in common locations
292
- import subprocess
293
- try:
294
- result = subprocess.run(['which', 'chromedriver'], capture_output=True, text=True)
295
- if result.returncode == 0:
296
- chromedriver_path = result.stdout.strip()
297
- service = Service(chromedriver_path)
298
- driver = webdriver.Chrome(service=service, options=options)
299
- else:
300
- raise Exception("ChromeDriver not found in PATH")
301
- except Exception as e2:
302
- print(f"All ChromeDriver attempts failed: {e2}")
303
- raise
304
 
305
  driver.get(url)
306
 
 
16
  from webdriver_manager.chrome import ChromeDriverManager
17
 
18
  os.environ["SE_CACHE_PATH"] = "/tmp/selenium"
 
 
 
 
19
 
20
  app = Flask(__name__)
21
  CORS(app)
 
266
  options.add_argument("--disable-dev-shm-usage")
267
  options.add_argument("--remote-debugging-port=9222")
268
 
269
+ # Use webdriver-manager to automatically handle ChromeDriver
270
+ service = Service(ChromeDriverManager().install())
271
+ driver = webdriver.Chrome(service=service, options=options)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
272
 
273
  driver.get(url)
274