Skip to content

Instantly share code, notes, and snippets.

@angww
Created July 2, 2019 04:01
Show Gist options
  • Save angww/9ec21bef424ecaa0981131c49b8d8415 to your computer and use it in GitHub Desktop.
Save angww/9ec21bef424ecaa0981131c49b8d8415 to your computer and use it in GitHub Desktop.
Scrape the old Motorola Modem SBV-5121 using chromedp for implement a log of de Internet status.
package main
import (
"context"
"log"
"strings"
"github.com/chromedp/chromedp"
)
func main() {
// create context
ctx, cancel := chromedp.NewContext(context.Background())
defer cancel()
// run task list
var res [10]string
err := chromedp.Run(ctx,
// First inject login
chromedp.Navigate(`http://192.168.100.1/loginData.htm?loginUsername=admin&loginPassword=motorola&LOGIN_BUTTON=Login`),
// Then open Signal information frameset
chromedp.Navigate(`http://192.168.100.1/cmSignalData.htm`),
// Wait to load footer image (I think is the last element to load.)
chromedp.WaitVisible(`body > table:nth-child(17) > tbody > tr:nth-child(1) > td > center > img`),
// Copy first element
chromedp.Text(`center:nth-child(7) > table > tbody > tr:nth-child(2) > td:nth-child(2)`, &res[0], chromedp.NodeVisible, chromedp.ByQueryAll),
chromedp.Text(`center:nth-child(7) > table > tbody > tr:nth-child(3) > td:nth-child(2)`, &res[1], chromedp.NodeVisible, chromedp.ByQueryAll),
chromedp.Text(`center:nth-child(7) > table > tbody > tr:nth-child(4) > td:nth-child(2)`, &res[2], chromedp.NodeVisible, chromedp.ByQueryAll),
chromedp.Text(`center:nth-child(7) > table > tbody > tr:nth-child(5) > td:nth-child(2)`, &res[3], chromedp.NodeVisible, chromedp.ByQueryAll),
chromedp.Text(`center:nth-child(7) > table > tbody > tr:nth-child(6) > td:nth-child(2)`, &res[4], chromedp.NodeVisible, chromedp.ByQueryAll),
chromedp.Text(`center:nth-child(9) > table > tbody > tr:nth-child(2) > td:nth-child(2)`, &res[5], chromedp.NodeVisible, chromedp.ByQueryAll),
chromedp.Text(`center:nth-child(9) > table > tbody > tr:nth-child(3) > td:nth-child(2)`, &res[6], chromedp.NodeVisible, chromedp.ByQueryAll),
chromedp.Text(`center:nth-child(9) > table > tbody > tr:nth-child(4) > td:nth-child(2)`, &res[7], chromedp.NodeVisible, chromedp.ByQueryAll),
chromedp.Text(`center:nth-child(9) > table > tbody > tr:nth-child(5) > td:nth-child(2)`, &res[8], chromedp.NodeVisible, chromedp.ByQueryAll),
chromedp.Text(`center:nth-child(9) > table > tbody > tr:nth-child(6) > td:nth-child(2)`, &res[9], chromedp.NodeVisible, chromedp.ByQueryAll),
)
if err != nil {
log.Fatal(err)
}
// Remove extra info from one cell
res[4] = string([]rune(res[4])[0:10])
var strs []string
for _, kval := range res {
strs = append(strs, strings.TrimSpace(kval))
}
log.Println(strings.Join(strs, "\t"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment