Spaces:
Sleeping
Sleeping
we are so close
Browse files- Dockerfile +2 -2
- app.py +35 -4
Dockerfile
CHANGED
|
@@ -18,8 +18,8 @@ RUN pip install -r requirements.txt
|
|
| 18 |
ENV PLAYWRIGHT_BROWSERS_PATH=/tmp/playwright-browsers
|
| 19 |
RUN playwright install chromium
|
| 20 |
|
| 21 |
-
# Verify the installation
|
| 22 |
-
RUN playwright --version && ls -la /tmp/playwright-browsers/
|
| 23 |
|
| 24 |
COPY . .
|
| 25 |
|
|
|
|
| 18 |
ENV PLAYWRIGHT_BROWSERS_PATH=/tmp/playwright-browsers
|
| 19 |
RUN playwright install chromium
|
| 20 |
|
| 21 |
+
# Verify the installation and show the exact path
|
| 22 |
+
RUN playwright --version && ls -la /tmp/playwright-browsers/ && find /tmp/playwright-browsers/ -name "chrome" -type f
|
| 23 |
|
| 24 |
COPY . .
|
| 25 |
|
app.py
CHANGED
|
@@ -254,10 +254,41 @@ def seek():
|
|
| 254 |
}
|
| 255 |
# Use Playwright to handle redirects and wait for page to load
|
| 256 |
with sync_playwright() as p:
|
| 257 |
-
browser
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
page = browser.new_page()
|
| 262 |
page.goto(url)
|
| 263 |
|
|
|
|
| 254 |
}
|
| 255 |
# Use Playwright to handle redirects and wait for page to load
|
| 256 |
with sync_playwright() as p:
|
| 257 |
+
# Let Playwright find the browser automatically
|
| 258 |
+
try:
|
| 259 |
+
browser = p.chromium.launch(headless=True)
|
| 260 |
+
except Exception as e:
|
| 261 |
+
print(f"Failed to launch with default path: {e}")
|
| 262 |
+
# Fallback: try to find the browser manually
|
| 263 |
+
import os
|
| 264 |
+
import glob
|
| 265 |
+
|
| 266 |
+
# Check what's actually in the playwright-browsers directory
|
| 267 |
+
if os.path.exists("/tmp/playwright-browsers"):
|
| 268 |
+
print("Contents of /tmp/playwright-browsers:")
|
| 269 |
+
os.system("find /tmp/playwright-browsers -type f -name 'chrome' -o -name 'chromium' -o -name 'headless_shell'")
|
| 270 |
+
|
| 271 |
+
# Try different common paths
|
| 272 |
+
possible_paths = [
|
| 273 |
+
"/tmp/playwright-browsers/chromium-*/chrome-linux/chrome",
|
| 274 |
+
"/tmp/playwright-browsers/chromium-*/chrome-linux/headless_shell",
|
| 275 |
+
"/tmp/playwright-browsers/chromium-*/chrome-linux/chromium"
|
| 276 |
+
]
|
| 277 |
+
|
| 278 |
+
for pattern in possible_paths:
|
| 279 |
+
paths = glob.glob(pattern)
|
| 280 |
+
if paths:
|
| 281 |
+
print(f"Found executable with pattern {pattern}: {paths[0]}")
|
| 282 |
+
try:
|
| 283 |
+
browser = p.chromium.launch(headless=True, executable_path=paths[0])
|
| 284 |
+
break
|
| 285 |
+
except Exception as e2:
|
| 286 |
+
print(f"Failed with {paths[0]}: {e2}")
|
| 287 |
+
else:
|
| 288 |
+
raise Exception("Could not find working Chrome executable")
|
| 289 |
+
else:
|
| 290 |
+
raise Exception("/tmp/playwright-browsers directory does not exist")
|
| 291 |
+
|
| 292 |
page = browser.new_page()
|
| 293 |
page.goto(url)
|
| 294 |
|