From c980fd0e775e2d61d4bd88f7cc85f29717b0d1e6 Mon Sep 17 00:00:00 2001 From: Jon Keys Date: Tue, 25 Feb 2025 18:26:36 -0800 Subject: [PATCH] use playwright if available when invoking scraper via cli --- aider/gui.py | 4 ++-- aider/scrape.py | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/aider/gui.py b/aider/gui.py index 7fa90bc38..6c5b012dc 100755 --- a/aider/gui.py +++ b/aider/gui.py @@ -11,7 +11,7 @@ from aider.coders import Coder from aider.dump import dump # noqa: F401 from aider.io import InputOutput from aider.main import main as cli_main -from aider.scrape import Scraper +from aider.scrape import Scraper, has_playwright class CaptureIO(InputOutput): @@ -484,7 +484,7 @@ class GUI: url = self.web_content if not self.state.scraper: - self.scraper = Scraper(print_error=self.info) + self.scraper = Scraper(print_error=self.info, playwright_available=has_playwright()) content = self.scraper.scrape(url) or "" if content.strip(): diff --git a/aider/scrape.py b/aider/scrape.py index 7977a8548..04e44bc81 100755 --- a/aider/scrape.py +++ b/aider/scrape.py @@ -14,7 +14,7 @@ aider_user_agent = f"Aider/{__version__} +{urls.website}" # platforms. -def install_playwright(io): +def check_env(): try: from playwright.sync_api import sync_playwright @@ -29,6 +29,16 @@ def install_playwright(io): except Exception: has_chromium = False + return has_pip, has_chromium + + +def has_playwright(): + has_pip, has_chromium = check_env() + return has_pip and has_chromium + + +def install_playwright(io): + has_pip, has_chromium = check_env() if has_pip and has_chromium: return True @@ -261,7 +271,7 @@ def slimdown_html(soup): def main(url): - scraper = Scraper() + scraper = Scraper(playwright_available=has_playwright()) content = scraper.scrape(url) print(content)