mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-01 02:05:00 +00:00

# Aider chat conversation: USER: include a check to see if playwright needs to install chromium and it's deps ASSISTANT: Here is the updated `playw.py` file with the check to see if Playwright needs to install Chromium and its dependencies: ```diff --- playw.py +++ playw.py @@ ... @@ import sys +from playwright.__main__ import main as playwright_install def main(url): + # Check if Chromium is installed, if not, install it + try: + with sync_playwright() as p: + p.chromium.launch() + except Exception as e: + print("Chromium is not installed. Installing necessary dependencies...") + playwright_install(['install', 'chromium']) + with sync_playwright() as p: browser = p.chromium.launch() page = browser.new_page() page.goto(url) content = page.content() print(content) browser.close() if __name__ == "__main__": if len(sys.argv) < 2: print("Usage: python playw.py <URL>") sys.exit(1) main(sys.argv[1]) ``` This diff adds a check before the main function to see if Chromium can be launched. If an exception occurs, it assumes Chromium is not installed and proceeds to install it using Playwright's command-line interface.
26 lines
780 B
Python
26 lines
780 B
Python
from playwright.sync_api import sync_playwright
|
|
import sys
|
|
from playwright.__main__ import main as playwright_install
|
|
|
|
def main(url):
|
|
# Check if Chromium is installed, if not, install it
|
|
try:
|
|
with sync_playwright() as p:
|
|
p.chromium.launch()
|
|
except Exception as e:
|
|
print("Chromium is not installed. Installing necessary dependencies...")
|
|
playwright_install(['install', 'chromium'])
|
|
|
|
with sync_playwright() as p:
|
|
browser = p.chromium.launch()
|
|
page = browser.new_page()
|
|
page.goto(url)
|
|
content = page.content()
|
|
print(content)
|
|
browser.close()
|
|
|
|
if __name__ == "__main__":
|
|
if len(sys.argv) < 2:
|
|
print("Usage: python playw.py <URL>")
|
|
sys.exit(1)
|
|
main(sys.argv[1])
|