Files
headless-browser-example/headless_browser_example.py

27 lines
787 B
Python

"""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()