Created
July 23, 2017 20:34
-
-
Save suntong/10c84a27844474bc38288b99659c766e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"log" | |
cdp "github.com/knq/chromedp" | |
) | |
func main() { | |
var err error | |
// create context | |
ctxt, cancel := context.WithCancel(context.Background()) | |
defer cancel() | |
// create chrome instance | |
c, err := cdp.New(ctxt, cdp.WithLog(log.Printf)) | |
if err != nil { | |
log.Fatal(err) | |
} | |
// run task list | |
var res string | |
err = c.Run(ctxt, submitNoip(&res)) | |
if err != nil { | |
log.Fatal(err) | |
} | |
// shutdown chrome | |
err = c.Shutdown(ctxt) | |
if err != nil { | |
log.Fatal(err) | |
} | |
// wait for chrome to finish | |
err = c.Wait() | |
if err != nil { | |
log.Fatal(err) | |
} | |
log.Printf("got: `%s`", res) | |
} | |
func submitNoip(res *string) cdp.Tasks { | |
return cdp.Tasks{ | |
cdp.Navigate("https://www.noip.com/login"), | |
// for / main page | |
// cdp.WaitVisible(`#copyright`), | |
// cdp.Click(`#loginModal`, cdp.NodeVisible), | |
// for /login page | |
cdp.WaitVisible(`#sign-up-footer`), | |
cdp.WaitVisible(`input[name="password"]`), | |
cdp.SendKeys(`input[name="username"]`, "MyNoipUsername"), | |
cdp.SendKeys(`input[name="password"]`, "yNoipPass"), | |
cdp.Click(`button[type="submit"]`), | |
// cdp.WaitNotPresent(`//*[@id="code_search"]/h2/svg`), | |
// cdp.Text(`//*[@id="js-pjax-container"]/div[2]/div/div[2]/ul/li/p`, res), | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment