examples

module
v0.0.0-...-e3ce5c9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2024 License: MIT

README

About chromedp examples

This folder contains a variety of code examples for working with chromedp. The package documentation contains a number of simple examples which are self-contained, while this repository holds more complex examples which tend to require internet access or external components.

Please note that these examples may break occassionally. Additionally, since these examples are written for specific websites, there is a good chance that the current selectors, etc. break after the website they are written against changes.

While every effort is made to ensure that these examples are kept up-to-date, it is expected that the examples made available here may occasionally break.

To file issues, use the chromedp's issue tracker.

Building and Running an Example

You can build and run these examples in the usual Go way:

# retrieve examples
$ go get -u -d github.com/chromedp/examples

# run example <prog>
$ go run $GOPATH/src/github.com/chromedp/examples/<prog>/main.go

# build example <prog>
$ go build -o <prog> github.com/chromedp/examples/<prog> && ./<prog>
Available Examples

The following examples are currently available:

Example Description
click use a selector to click on an element
cookie set a HTTP cookie on requests
download_file do headless file downloads
download_image do headless image downloads
emulate emulate a specific device such as an iPhone
eval evaluate javascript and retrieve the result
fast extract and render data from a page
forecast extract and render data from a page
geoip extract and render data from a page
headers add extra HTTP headers to browser requests
keys send key events to an element
latlon retrieve the latitude/longitude from google maps, using the browser's target events
logic more complex logic beyond simple actions
multi use headless-shell and a container (Docker, Podman, other)
pdf capture a pdf of a page
proxy authenticate a proxy server which requires authentication
remote connect to an existing Chrome DevTools instance using a remote WebSocket URL
screenshot take a screenshot of a specific element and of the entire browser viewport
submit fill out and submit a form
subtree populate and travel a subtree of the DOM
text extract text from a specific element
upload upload a file on a form
visible wait until an element is visible

Contributing

Pull Requests and contributions to this project are encouraged and greatly welcomed! The chromedp project always needs new examples, and needs talented developers (such as yourself!) to submit fixes for the existing examples when they break (for example, when a website's layout/HTML changes).

Directories

Path Synopsis
Command click is a chromedp example demonstrating how to use a selector to click on an element.
Command click is a chromedp example demonstrating how to use a selector to click on an element.
Command cookie is a chromedp example demonstrating how to set a HTTP cookie on requests.
Command cookie is a chromedp example demonstrating how to set a HTTP cookie on requests.
Command download_file is a chromedp example demonstrating how to do headless file downloads.
Command download_file is a chromedp example demonstrating how to do headless file downloads.
Command download_image is a chromedp example demonstrating how to do headless image downloads.
Command download_image is a chromedp example demonstrating how to do headless image downloads.
Command emulate is a chromedp example demonstrating how to emulate a specific device such as an iPhone.
Command emulate is a chromedp example demonstrating how to emulate a specific device such as an iPhone.
Command eval is a chromedp example demonstrating how to evaluate javascript and retrieve the result.
Command eval is a chromedp example demonstrating how to evaluate javascript and retrieve the result.
Command fast is a chromedp example demonstrating how to extract and render data from a page.
Command fast is a chromedp example demonstrating how to extract and render data from a page.
Command forecast is a chromedp example demonstrating how to extract and render data from a page.
Command forecast is a chromedp example demonstrating how to extract and render data from a page.
Command forecast is a chromedp example demonstrating how to extract and render data from a page.
Command forecast is a chromedp example demonstrating how to extract and render data from a page.
Command headers is a chromedp example demonstrating how to add extra HTTP headers to browser requests.
Command headers is a chromedp example demonstrating how to add extra HTTP headers to browser requests.
Command keys is a chromedp example demonstrating how to send key events to an element.
Command keys is a chromedp example demonstrating how to send key events to an element.
Command latlon is a chromedp example demonstrating how to retrieve the latitude/longitude from google maps, using the browser's target events.
Command latlon is a chromedp example demonstrating how to retrieve the latitude/longitude from google maps, using the browser's target events.
Command logic is a chromedp example demonstrating more complex logic beyond simple actions.
Command logic is a chromedp example demonstrating more complex logic beyond simple actions.
Command multi is a chromedp example demonstrating how to use headless-shell and a container (Docker, Podman, other).
Command multi is a chromedp example demonstrating how to use headless-shell and a container (Docker, Podman, other).
Command pdf is a chromedp example demonstrating how to capture a pdf of a page.
Command pdf is a chromedp example demonstrating how to capture a pdf of a page.
Command proxy is a chromedp example demonstrating how to authenticate a proxy server which requires authentication.
Command proxy is a chromedp example demonstrating how to authenticate a proxy server which requires authentication.
Command remote is a chromedp example demonstrating how to connect to an existing Chrome DevTools instance using a remote WebSocket URL.
Command remote is a chromedp example demonstrating how to connect to an existing Chrome DevTools instance using a remote WebSocket URL.
Command screenshot is a chromedp example demonstrating how to take a screenshot of a specific element and of the entire browser viewport.
Command screenshot is a chromedp example demonstrating how to take a screenshot of a specific element and of the entire browser viewport.
Command submit is a chromedp example demonstrating how to fill out and submit a form.
Command submit is a chromedp example demonstrating how to fill out and submit a form.
Command subtree is a chromedp example demonstrating how to populate and travel a subtree of the DOM.
Command subtree is a chromedp example demonstrating how to populate and travel a subtree of the DOM.
Command text is a chromedp example demonstrating how to extract text from a specific element.
Command text is a chromedp example demonstrating how to extract text from a specific element.
Command upload is a chromedp example demonstrating how to upload a file on a form.
Command upload is a chromedp example demonstrating how to upload a file on a form.
Command visible is a chromedp example demonstrating how to wait until an element is visible.
Command visible is a chromedp example demonstrating how to wait until an element is visible.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL