Skip to content

chromedp

10,591 6 107 MIT
chromedp (5 Aug 2023) Aug 15 2019 58.1 thousand (month)

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.

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)
}

Alternatives / Similar


Other Languages

62,856 1.44.1 (a month ago) Jan 23 2015 compare
29,780 4.22.0 (24 days ago) Apr 25 2008 compare
11,134 1.45.0 (12 days ago) Feb 24 2021 compare
9,064 3.5.5 (4 months ago) Sep 04 2020 compare
1,823 0.4.0 (5 months ago) Dec 28 2012 compare
2,907 v2.1.1 (7 months ago) Jul 17 2018 compare
411 1.9.3.1 (a month ago) Jul 22 2022 compare
4,039 3.5 (4 years ago) Apr 25 2014 compare
Was this page helpful?