• Stars
    star
    116
  • Rank 303,894 (Top 6 %)
  • Language
    Go
  • License
    MIT License
  • Created about 7 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Go package for working with headless Chrome. Run interactive JavaScript commands on web pages with Go and Chrome.

DO NOT USE! This project does not work anymore due to changes in Chrome. Use the Chrome DevTools protocol in chromedp instead!

headlessChrome πŸ€–

Support only for Ubuntu on Docker for now. Mac appears to not be working. 😬

A go package for working with headless Chrome. Run interactive JavaScript commands on pages with go and Chrome without a GUI. Includes a few helpful functions out of the box to query and click selector paths by their classes, divs, or html content.

You could use this package to click buttons and scrape content on/from a website as if you were a browser, or to render pages that wouldn't be supported by other things like phantomjs or casperjs. Especially useful for sites that use EmberJS, where the content is rendered by javascript after the HTML payload is delivered.

Examples

An example project that does some simple things with a Makefile and Dockerfile is in the examples directory.

Install

go get github.com/integrii/headlessChrome

Documentation

http://godoc.org/github.com/integrii/headlessChrome

Docker Version

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.

Custom Flags

By default, we startup with the bare minimum flags necessary to start headless chrome and open a javascript console. If you want more flags, like a resolution size, or a custom User-Agent, you can specify it by replacing the 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 variable.

headlessChrome.ChromePath = `/opt/google/chrome-unstable/chrome`
JavaScript Helper Examples

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)

Contributing

Please send pull requests! It would be good to have support for more operating systems or more handy helpers to run more commonly used javascript code easily. Adding support for other operating systems should be as simple as checking the platform type and changing the ChromePath variable's default value.

More Repositories

1

flaggy

Idiomatic Go input parsing with subcommands, positional values, and flags at any position. No required project or package layout and no external dependencies.
Go
831
star
2

wormhole

πŸ› πŸ•³ Transparent TCP redirection. Makes a wormhole between one TCP socket to another transparently. Can be used to redirect SSH, MySQL, or anything else TCP.
Go
38
star
3

go-redis-migrator

A cluster aware Redis key migrator. Moves keys from one cluster or host to another cluster or host.
Go
33
star
4

FreeTakServerContainer

A docker container for FreeTakServer
Dockerfile
15
star
5

serve

πŸ•Έ A robust and handy tool for serving your current terminal directory over HTTP
Go
13
star
6

A858DE45F56D9BC9

Attempting to decode the mysterious /r/A858DE45F56D9BC9 subreddit data
Ruby
12
star
7

go-k8s-graceful-termination

Kubernetes application example. Does not drop connections when terminating. Implemented in Go.
Go
11
star
8

bashgame

A command line game written in bash. Great for learning to use github and bash!
Shell
8
star
9

LightningPHP

LightningPHP is an HHVM compatible, minimal MVC framework that is obsessed with speed.
PHP
7
star
10

homebackup

Family picture management and backup. De-duplicates, sorts and backs up your home picture and video share.
Shell
6
star
11

cadvisor-daemonset

A kubernetes daemonset for cadvisor which exposes a web interface on every node.
5
star
12

ikiwiki

A Chef cookbook for deploying ikiwiki with bootstrap 3 and git backend
Perl
5
star
13

interactive

🐚 Execute and interact with any command line program using Go channels.
Go
4
star
14

.vim

A simple but useful vim setup that has few conflicts, overrides, or complicated configs.
Vim Script
3
star
15

define

Defines the supplied word on the command line. Golang.
Go
3
star
16

folio-gallery

My adaptations to folio-gallery from http://www.foliopages.com/php-jquery-ajax-photo-gallery-no-database
PHP
1
star
17

go-test-bug

Demonstrates a bug in argument passing in go test
Go
1
star