From 9d236d44adc1f1cc97b63d8893598a40c07149e0 Mon Sep 17 00:00:00 2001 From: Grok Date: Sun, 10 Aug 2025 12:04:03 +0000 Subject: [PATCH] Add example headless browsing script --- headless_browser_example.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 headless_browser_example.py diff --git a/headless_browser_example.py b/headless_browser_example.py new file mode 100644 index 0000000..e13fcfe --- /dev/null +++ b/headless_browser_example.py @@ -0,0 +1,26 @@ +"""Example Python script for headless browsing using Playwright on Linux. + +This script launches a headless Chromium browser, navigates to a webpage, +prints the page title, and closes the browser. + +Requirements: +- Python 3.8+ +- Playwright library: pip install playwright +- Install browsers: playwright install + +Optimized for low resource usage. +""" + +from playwright.sync_api import sync_playwright + +def main(): + with sync_playwright() as p: + # Launch headless browser with minimal options for efficiency + browser = p.chromium.launch(headless=True, args=['--no-sandbox', '--disable-gpu']) + page = browser.new_page() + page.goto('https://example.com') + print(f"Page title: {page.title()}") + browser.close() + +if __name__ == '__main__': + main()