chromedp instead!DO NOT USE! This project does not work anymore due to changes in Chrome. Use the Chrome DevTools protocol in
Support only for Ubuntu on Docker for now. Mac appears to not be working.
An example project that does some simple things with a
Dockerfile is in the examples directory.
go get github.com/integrii/headlessChrome
To run Chrome headless with docker, check out
examples/docker/main.go as well as
examples/docker/Makefile. When in that directory, you can do
make test to build and run the container with the example app inside. You will see the source of httpbin.org displayed at the end of the build and run.
Args variable. Just be sure to append to it so you don't kill the default flags...
headlessChrome.Args = append(headlessChrome.Args,"--user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36") headlessChrome.Args = append(headlessChrome.Args,"--window-size=1024,768")
Changing the Path to Chrome
Change the path to Chrome by simply setting the
headlessChrome.ChromePath = `/opt/google/chrome-unstable/chrome`
Find the full list in the docs.
// click some span element from the page by its text content browser.ClickItemWithInnerHTML("span", "Google Search",0) // select the content of something by its css classes browser.GetContentOfItemWithClasses("button arrow bold",0) time.Sleep(time.Second) // give it a second to query // read the selected stuff from the console by picking // the next item from the output channel fmt.Println(<-browser.Output)
ChromePath variable's default value.