Skip to content

chromedpvsplaywright

MIT 131 6 10,993
58.1 thousand (month) Nov 27 2019 chromedp(12 days ago)
11,763 5 35 Apache-2.0
Feb 24 2021 5.5 million (month) 1.48.0(6 days ago)

ChromeDP is an open-source library for driving browsers using the Chrome DevTools Protocol (CDP) in the Go programming language. It is a high-level library that abstracts away the low-level details of interacting with the CDP and provides a simple, intuitive API for performing common browser automation tasks such as clicking elements, filling out forms, and taking screenshots.

ChromeDP also supports parallel execution of browser tasks, making it well-suited for large-scale web scraping and testing applications. It is considered as one of the most popular Go package for automation and scraping tasks.

playwright is a Python package that allows developers to automate web browsers for end-to-end testing, web scraping, and web performance analysis. It is built on top of WebKit, Mozilla's Gecko, and Microsoft's EdgeHTML, and it is designed to be fast, reliable, and easy to use.

playwright is similar to Selenium, but it provides a more modern and powerful API, with features such as automatic waiting for elements, automatic retries, and built-in support for browser contexts, which allow you to open multiple pages in a single browser instance.

Playwright also provides an asynchronous client which makes scaling playwright-powered web scrapers easier than alternatives (like Selenium)

Example Use


package main

import (
  "context"
  "fmt"

  "github.com/chromedp/chromedp"
)

func main() {
  var title, firstParagraph string

  // create context
  ctx, cancel := chromedp.NewContext(context.Background())
  defer cancel()

  // run task list (a scraping scenario)
  err := chromedp.Run(ctx,
    // go to page
    chromedp.Navigate("https://www.example.com"),
    // wait for element to load
    chromedp.WaitVisible("body"),
    // extract text from an element (css selector)
    chromedp.Text("title", &title),
    // extract first paragraph element
    chromedp.First(chromedp.ByTagName("p"), &firstParagraph),
  )
  if err != nil {
    fmt.Println("error:", err)
    return
  }

  fmt.Printf("Title: %s\n", title)
  fmt.Printf("First paragraph: %s\n", firstParagraph)
}
from playwright import sync_playwright

# Start Playwright
with sync_playwright() as playwright:
    # Launch a browser instance
    browser = playwright.chromium.launch()
    # Open a new context (tab)
    context = browser.new_context()
    # Create a new page in the context
    page = context.new_page()

    # Navigate to a website
    page.goto("https://www.example.com")

    # Find an element by its id
    element = page.get_by_id("example-id")

    # Interact with the element
    element.click()

    # Fill an input form
    page.get_by_name("example-name").fill("example text")

    # Find and click a button
    page.get_by_xpath("//button[text()='Search']").click()

    # Wait for the page to load
    page.wait_for_selector("#results")

    # Get the page title
    print(page.title)

    # Close the browser
    browser.close()

Alternatives / Similar


Was this page helpful?