Spaces:
Sleeping
Sleeping
cw ,j,ab ecwewbhlewdbh
Browse files
app.py
CHANGED
|
@@ -254,19 +254,50 @@ def seek():
|
|
| 254 |
}
|
| 255 |
# Use Playwright to handle redirects and wait for page to load
|
| 256 |
with sync_playwright() as p:
|
| 257 |
-
#
|
| 258 |
import glob
|
| 259 |
-
|
| 260 |
-
if not chrome_paths:
|
| 261 |
-
raise Exception("Chrome executable not found in /root/.cache/ms-playwright/")
|
| 262 |
|
| 263 |
-
|
| 264 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
|
| 271 |
page = browser.new_page()
|
| 272 |
page.goto(url)
|
|
|
|
| 254 |
}
|
| 255 |
# Use Playwright to handle redirects and wait for page to load
|
| 256 |
with sync_playwright() as p:
|
| 257 |
+
# Find where Playwright actually installed Chrome
|
| 258 |
import glob
|
| 259 |
+
import os
|
|
|
|
|
|
|
| 260 |
|
| 261 |
+
# Try different possible locations
|
| 262 |
+
possible_locations = [
|
| 263 |
+
"/root/.cache/ms-playwright/chromium-*/chrome-linux/chrome",
|
| 264 |
+
"/home/user/.cache/ms-playwright/chromium-*/chrome-linux/chrome",
|
| 265 |
+
"/tmp/playwright-browsers/chromium-*/chrome-linux/chrome",
|
| 266 |
+
"/usr/lib/chromium-browser/chromium-browser",
|
| 267 |
+
"/usr/bin/chromium-browser"
|
| 268 |
+
]
|
| 269 |
|
| 270 |
+
executable_path = None
|
| 271 |
+
for pattern in possible_locations:
|
| 272 |
+
if "*" in pattern:
|
| 273 |
+
paths = glob.glob(pattern)
|
| 274 |
+
if paths:
|
| 275 |
+
executable_path = paths[0]
|
| 276 |
+
print(f"Found Chrome at: {executable_path}")
|
| 277 |
+
break
|
| 278 |
+
else:
|
| 279 |
+
if os.path.exists(pattern):
|
| 280 |
+
executable_path = pattern
|
| 281 |
+
print(f"Found Chrome at: {executable_path}")
|
| 282 |
+
break
|
| 283 |
+
|
| 284 |
+
if not executable_path:
|
| 285 |
+
# Debug: show what's actually there
|
| 286 |
+
print("Chrome not found. Checking directories:")
|
| 287 |
+
for check_dir in ["/root/.cache", "/home", "/tmp", "/usr/bin"]:
|
| 288 |
+
if os.path.exists(check_dir):
|
| 289 |
+
print(f"Contents of {check_dir}:")
|
| 290 |
+
os.system(f"find {check_dir} -name '*chrome*' -o -name '*chromium*' 2>/dev/null | head -10")
|
| 291 |
+
|
| 292 |
+
# Try to let Playwright find it automatically
|
| 293 |
+
try:
|
| 294 |
+
browser = p.chromium.launch(headless=True)
|
| 295 |
+
print("Playwright found Chrome automatically")
|
| 296 |
+
except Exception as e:
|
| 297 |
+
raise Exception(f"Chrome not found anywhere and Playwright can't find it: {e}")
|
| 298 |
+
else:
|
| 299 |
+
browser = p.chromium.launch(headless=True, executable_path=executable_path)
|
| 300 |
+
print(f"Using Chrome executable: {executable_path}")
|
| 301 |
|
| 302 |
page = browser.new_page()
|
| 303 |
page.goto(url)
|