Skip to content

admpub/cr

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cr

Simple wrapper for chromedp.

Licence: BSD.

Example usage:

package main

import (
    "log"
    "time"

    "github.com/admpub/cr"
)

func main() {

    browser, err := cr.New()
    if err != nil {
        log.Fatalf("Unable to create browser: %s\n", err)
    }
    defer browser.Close()

    if err := browser.Navigate("https://google.com"); err != nil {
        log.Fatalf("Couldn't navigate to page: %s\n", err)
    }

    if err := browser.SendKeys("//input[@id='lst-ib']", "The Big Lebowski"); err != nil {
        log.Fatalf("Couldn't fill out form: %s\n", err)
    }

    if err = browser.Click("//input[@name='btnK']"); err != nil {
        log.Fatalf("Couldn't find the submit button: %s\n", err)
    }
    time.Sleep(time.Second * 15)

}

Why XPath?

XPath seems to be the easiest way to find DOM elements. There is great documentation online, such as the w3schools tutorial, and Google searches for specific things tend to turn up good results.

It is also easy to find an XPath in Chrome by right-clicking on an element and selecting "Inspect."

Clicking on any element in the inspector will show three dots (...) that you can click on and select "Copy XPath" from the "Copy" menu.

Typing CTRL+f in the inspector will provide a text box which can be used to test XPath values before running your code.

About

Simplified wrapper for chromedp

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%