-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_playwright.py
More file actions
80 lines (69 loc) · 2.99 KB
/
setup_playwright.py
File metadata and controls
80 lines (69 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python3
"""
Setup script for Playwright browsers
Run this after installing requirements to download browser binaries
"""
import subprocess
import sys
import os
def install_playwright_browsers():
"""Install Playwright browser binaries"""
print("Installing Playwright browser binaries...")
try:
# Install browsers
result = subprocess.run([
sys.executable, "-m", "playwright", "install"
], check=True, capture_output=True, text=True)
print("✅ Playwright browsers installed successfully!")
print(result.stdout)
# Install system dependencies (for Linux)
if os.name == 'posix' and sys.platform != 'darwin':
print("\nInstalling system dependencies...")
try:
subprocess.run([
sys.executable, "-m", "playwright", "install-deps"
], check=True, capture_output=True, text=True)
print("✅ System dependencies installed!")
except subprocess.CalledProcessError as e:
print(f"⚠️ System dependencies installation failed: {e}")
print("You may need to install them manually:")
print("sudo apt-get install libnss3 libatk-bridge2.0-0 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 libxrandr2 libgbm1 libxss1 libasound2")
return True
except subprocess.CalledProcessError as e:
print(f"❌ Failed to install Playwright browsers: {e}")
print(f"Error output: {e.stderr}")
return False
except FileNotFoundError:
print("❌ Playwright not found. Please install it first:")
print("pip install playwright")
return False
def check_playwright_installation():
"""Check if Playwright is properly installed"""
try:
import playwright
print("✅ Playwright installed successfully")
return True
except ImportError:
print("❌ Playwright not installed. Please run:")
print("pip install playwright")
return False
def main():
print("🦕 DataSaurus Playwright Setup")
print("=" * 40)
# Check if Playwright is installed
if not check_playwright_installation():
sys.exit(1)
# Install browsers
if install_playwright_browsers():
print("\n🎉 Setup complete! You can now use Playwright for scraping.")
print("\nConfiguration options in backend/config.py:")
print("- PLAYWRIGHT_HEADLESS: True/False")
print("- PLAYWRIGHT_BROWSER: 'chromium', 'firefox', or 'webkit'")
print("- PLAYWRIGHT_VIEWPORT: {'width': 1920, 'height': 1080}")
print("- PLAYWRIGHT_WAIT_FOR_LOAD: 'load', 'domcontentloaded', or 'networkidle'")
print("- PLAYWRIGHT_SCREENSHOT: True/False (for debugging)")
else:
print("\n❌ Setup failed. Please check the errors above.")
sys.exit(1)
if __name__ == "__main__":
main()