Best Rod code snippet using rod.MustPage
bili.go
Source:bili.go
...14 FocusNumers int15}16func NewBiHandle() *BiliHandle {17 b := GetBrowser("user/bili" , false)18 page := b.MustPage("http://bilibili.com")19 login := !page.MustWaitLoad().MustHasR(".unlogin-avatar" , "ç»å½")20 return &BiliHandle{21 B: b,22 Page: page,23 IsLogin: login,24 }25}26//çå¾
ç¨æ·ç»å½27func (b *BiliHandle) WaitLogIn(){28 if b.IsLogin {29 b.B.MustPage("http://bilibili.com").MustElement(".bili-icon_dingdao_dengchu")30 }31}32//ææ¾è§é¢33func (b *BiliHandle) Play() {34 v := b.Page.MustElement(".video-card-reco a").MustAttribute("href")35 childPage := b.B.MustPage(fmt.Sprintf("http:%s" , *v))36 childPage.MustElement("#bilibiliPlayer").MustClick()37 childPage.MustElement(".bilibili-player-upinfo-span.restart")38 fmt.Print("vide play ending")39 childPage.Close()40 //b.MustPage()41}42//å享è§é¢43func (b *BiliHandle) Share () {44}45//ç¹èµè§é¢46func (b *BiliHandle) Like() {47 48}49type Dynamic struct {50 Time string `json:"time"`51 Content string `json:"content"`52}53// è大å¥å¨çä½ 54func (b *BiliHandle)BigBrotherIsWatchingYou(id string) {55 var dynamicArr []Dynamic56 var dynamicArrItme Dynamic57 scpage := b.B.MustPage(fmt.Sprintf("https://space.bilibili.com/%s/dynamic" ,id))58 for {59 scpage.Reload()60 dynamicArr = nil61 scpage.MustElement(".main-content")62 arr := scpage.MustElements(".main-content")63 for _ , v := range arr {64 dyTime := v.MustElement(".detail-link.tc-slate").MustText()65 content := v.MustElement(".card-content").MustText()66 dynamicItem := Dynamic{67 Time: dyTime,68 Content: content,69 }70 dynamicArr = append(dynamicArr , dynamicItem)71 }72 //ç¨åºç¬¬ä¸æ¬¡è¿è¡73 if(dynamicArrItme.Time == "" ){74 dynamicArrItme = dynamicArr[0]75 utils.WxSendMsg(string(`è大å¥å·²ç»å¼å§ççä»å¦ ï¼ æåä¸æ¡å¨ææ´æ°ä¸º` + dynamicArrItme.Time))76 fmt.Println("fir")77 }78 if dynamicArrItme.Time != dynamicArr[0].Time || dynamicArrItme.Content != dynamicArr[0].Content {79 fmt.Println("æ´æ°")80 utils.WxSendMsg(fmt.Sprintf("è大å¥åç°Taçå¨æå·²ç»æ´æ°å¦ ï¼ï¼ï¼ æ¶é´ä¸º ï¼ %s , å
容为 : %s " , dynamicArr[0].Time ,dynamicArr[0].Content))81 dynamicArrItme = dynamicArr[0]82 }83 rand.Seed(time.Now().UnixNano())84 time.Sleep(time.Second * 3 )85 }86}87//转åå¨æ88func (b *BiliHandle)Forward() {89 90}91//è·åæå
³æ³¨çå表92func (b *BiliHandle) GetFocus() {93 var rs []string94 spacePage := b.B.MustPage("http://space.bilibili.com")95 spacePage.MustElement(".n-statistics a").MustClick()96 spacePage.MustElement(".list-item")97 for{98 arr := spacePage.MustElements(".list-item")99 for _ , v := range arr {100 name , _ := v.MustElement(".fans-name").Text()101 rs = append(rs ,name)102 }103 if len(arr) == 20 {104 spacePage.MustElement(".be-pager-next").MustClick()105 time.Sleep(time.Second)106 }else {107 fmt.Println("ending...")108 spacePage.Close()109 break110 }111 }112 fmt.Println(rs)113 fmt.Printf( "ä¸å
±å
³æ³¨äººæ°ä¸º %d" , len(rs))114}115//æçç´æå
³æ³¨å表116func (b *BiliHandle) GetLiveFocus (){117 type LiveItme struct {118 Name string `json:"name"`119 Status string `json:"status"`120 }121 var rsString string122 cpage := b.B.MustPage("https://link.bilibili.com/p/center/index#/user-center/follow/1")123 for{124 var liveArr []LiveItme125 cpage.Reload()126 cpage.MustElement(".favourite-card")127 arr := cpage.MustElements(".favourite-card")128 for _ , v := range arr {129 liveArr = append(liveArr , LiveItme{130 Name: v.MustElement(".anchor-name").MustText(),131 Status: v.MustElement(".anchor-status").MustText(),132 })133 }134 rsByte , err := json.Marshal(liveArr)135 if err != nil {136 fmt.Println(err)...
go-rod-v2ex-example-main.go
Source:go-rod-v2ex-example-main.go
...45 lock.Lock()46 defer lock.Unlock()47 browser := newBrowser(true).Timeout(30 * time.Second)48 defer browser.Close()49 page := browser.MustPage(*topic)50 page.Element(".box")51 go page.HandleDialog(true, "")()52 wait := page.MustWaitRequestIdle()53 page.MustElementR(".box .fr a", "置顶 10 åé").MustClick()54 wait()55 log.Println("置顶äº", *topic)56}57func clockIn() {58 if !isLoggedIn() {59 login()60 }61 lock.Lock()62 defer lock.Unlock()63 browser := newBrowser(true)64 defer browser.Close()65 page := browser.Timeout(time.Minute).MustPage("https://www.v2ex.com/")66 el := page.MustElement(`[href="/mission/daily"]`, `.balance_area`)67 if el.MustMatches(`.balance_area`) {68 log.Println("å·²ç»ç¾è¿å°äº")69 return70 }71 el.MustClick()72 page.MustElementR("input", "é¢å X éå¸").MustClick()73 page.MustElementR(".message", "å·²æåé¢åæ¯æ¥ç»å½å¥å±")74 log.Println("ç¾å°æå")75}76func isLoggedIn() bool {77 lock.Lock()78 defer lock.Unlock()79 browser := newBrowser(true)80 defer browser.Close()81 return browser.MustPage("https://www.v2ex.com/signin").MustWaitLoad().MustHasR("a", "ç»åº|Sign Out")82}83func login() {84 lock.Lock()85 defer lock.Unlock()86 browser := newBrowser(false)87 defer browser.Close()88 browser.MustPage("https://www.v2ex.com/signin").MustElementR("a", "ç»åº|Sign Out")89}90func newBrowser(headless bool) *rod.Browser {91 url := launcher.New().Headless(headless).UserDataDir("tmp/user").MustLaunch()92 return rod.New().ControlURL(url).MustConnect()93}94func hour() int {95 return time.Now().In(locChina).Hour()96}...
main.go
Source:main.go
...21 lock.Lock()22 defer lock.Unlock()23 browser := newBrowser(true)24 defer browser.Close()25 page := browser.MustPage("https://www.futunn.com/account/home").MustWaitLoad()26 page.Race().Element("#signIn .none").MustHandle(func(el *rod.Element) {27 el.MustClick()28 log.Println("ç¾å°æå")29 }).ElementR("#signed", "å·²ç¾å°").MustHandle(func(el *rod.Element) {30 log.Println("å·²ç»ç¾è¿å°äº")31 }).MustDo()32}33func isLoggedIn() bool {34 lock.Lock()35 defer lock.Unlock()36 browser := newBrowser(true)37 defer browser.Close()38 return browser.MustPage("https://www.futunn.com").MustWaitLoad().MustHasR("a", "éåº|Sign Out")39}40func login() {41 lock.Lock()42 defer lock.Unlock()43 browser := newBrowser(false)44 defer browser.Close()45 page := browser.MustPage("https://passport.futunn.com/?target=https%3A%2F%2Fwww.futunn.com%2Faccount%2Fhome&lang=zh-hk#login")46 page.MustElement(`input[name=email]`).MustInput(*email)47 page.MustElement(`input[name=password]`).MustInput(*password).MustPress(input.Enter)48 page.Race().Element(".nn-header-account").MustHandle(func(e *rod.Element) {49 log.Println("ç»å½æåï¼å·²ç»æ¾å°ç»å½å页é¢å
ç´ å
容 ", e.MustText())50 }).Element(".u-error-wrapper").MustHandle(func(e *rod.Element) {51 // å½ç¨æ·åæå¯ç é误æ¶52 log.Println("失败")53 log.Panicln(e)54 log.Fatal(e.MustText())55 })56}57func newBrowser(headless bool) *rod.Browser {58 url := launcher.New().Headless(headless).UserDataDir("tmp/user").MustLaunch()59 return rod.New().ControlURL(url).MustConnect()...
MustPage
Using AI Code Generation
1import (2func main() {3 browser := rod.New().MustConnect()4 defer browser.MustClose()5 defer page.MustClose()6 page.MustWaitLoad()7 title := page.MustElement("title").MustText()8 println(title)9 input := page.MustElement("input[name=q]")10 input.MustInput("rod")11 input.MustPress(proto.InputKeyEnter)12 page.MustWaitLoad()13 title = page.MustElement("title").MustText()14 println(title)15}16import (17func main() {18 browser := rod.New().MustConnect()19 defer browser.MustClose()20 defer page.MustClose()21 page.MustWaitLoad()22 title := page.MustElement("title").MustText()23 println(title)24 input := page.MustElement("input[name=q]")25 input.MustInput("rod")26 input.MustPress(proto.InputKeyEnter)27 page.MustWaitLoad()28 title = page.MustElement("title").MustText()29 println(title)30}31import (32func main() {33 browser := rod.New().MustConnect()34 defer browser.MustClose()35 defer page.MustClose()36 page.MustWaitLoad()37 title := page.MustElement("
MustPage
Using AI Code Generation
1import (2func main() {3 l := launcher.New().Headless(false)4 defer l.Cleanup()5 browser := rod.New().Client(proto.CDPClient).Connect().MustPage(l.MustLaunch())6 defer browser.Close()7 title := browser.MustElement("title").MustText()8 fmt.Println(title)9}
MustPage
Using AI Code Generation
1import (2func main() {3 browser := rod.New().ControlURL(launcher.New().MustLaunch()).MustConnect()4 defer browser.MustClose()5 page.MustElement("input[name=q]").MustInput("rod").MustPress(input.Enter)6 page.MustElement("h3").MustClick()7 page.MustScreenshot("screenshot.png")8 page.MustClose()9}10import (11func main() {12 browser := rod.New().ControlURL(launcher.New().MustLaunch()).MustConnect()13 defer browser.MustClose()14 page.MustElement("input[name=q]").MustInput("rod").MustPress(input.Enter)15 page.MustElement("h3").MustClick()16 page.MustScreenshot("screenshot.png")17 page.MustClose()18}19import (20func main() {21 browser := rod.New().ControlURL(launcher.New().MustLaunch()).MustConnect()22 defer browser.MustClose()23 page.MustElement("input[name=q]").MustInput("rod").MustPress(input.Enter)24 page.MustElement("h3").MustClick()25 page.MustScreenshot("screenshot.png")26 page.MustClose()27}28import (29func main() {30 browser := rod.New().ControlURL(launcher.New().MustLaunch()).MustConnect()31 defer browser.MustClose()32 page.MustElement("input[name=q]").MustInput("rod").MustPress(input.Enter)33 page.MustElement("h3").MustClick()34 page.MustScreenshot("screenshot.png")35 page.MustClose()36}
MustPage
Using AI Code Generation
1import (2func main() {3 url := launcher.New().MustLaunch()4 browser := rod.New().ControlURL(url).MustConnect()5 fmt.Println(page.MustInfo().URL)6}7import (8func main() {9 url := launcher.New().MustLaunch()10 browser := rod.New().ControlURL(url).MustConnect()11 fmt.Println(page.MustInfo().URL)12}13import (14func main() {15 url := launcher.New().MustLaunch()16 browser := rod.New().ControlURL(url).MustConnect()17 page.MustEval(`document.querySelector("input[title='Search']").value = "Rod"`)18 fmt.Println(page.MustInfo().URL)19}20import (21func main() {22 url := launcher.New().MustLaunch()23 browser := rod.New().ControlURL(url).MustConnect()24 page.MustElement("input[title='Search']").MustInput("Rod")25 fmt.Println(page.MustInfo().URL)26}27import (28func main() {29 url := launcher.New().MustLaunch()30 browser := rod.New().ControlURL(url).MustConnect()
MustPage
Using AI Code Generation
1import (2func main() {3}4import (5func main() {6}7import (8func main() {9}10import (11func main() {12}13import (14func main() {15}16import (17func main() {18 utils.E(rod.New().MustConnect
MustPage
Using AI Code Generation
1import (2func main() {3 browser := rod.New().MustConnect()4 fmt.Println(page.MustTitle())5}6import (7func main() {8 browser := rod.New().MustConnect()9 fmt.Println(page.MustElement("input").MustAttribute("name"))10}11import (12func main() {13 browser := rod.New().MustConnect()14 fmt.Println(page.MustElementR("input", "name", "q").MustAttribute("name"))15}16import (17func main() {18 browser := rod.New().MustConnect()19 fmt.Println(page.MustElementX("/html/body/div[1]/div[3]/form/div[1]/div[1]/div[1]/div/div[2]/input").MustAttribute("name"))20}21import (22func main() {23 browser := rod.New().MustConnect()24 fmt.Println(page.MustElements("input"))25}26import (27func main() {28 browser := rod.New().MustConnect()29 fmt.Println(page.MustElementsR("input", "name", "q"))30}31import (
MustPage
Using AI Code Generation
1import (2func main() {3 browser := rod.New().ControlURL(launcher.New().MustLaunch()).MustConnect()4 html, err := page.HTML()5 if err != nil {6 log.Fatal(err)7 }8 fmt.Println(html)9}10import (11func main() {12 browser := rod.New().ControlURL(launcher.New().MustLaunch()).MustConnect()13 html, err := page.HTML()14 if err != nil {15 log.Fatal(err)16 }17 fmt.Println(html)18}19import (20func main() {21 browser := rod.New().ControlURL(launcher.New().MustLaunch()).MustConnect()22 html, err := page.HTML()23 if err != nil {24 log.Fatal(err)25 }26 fmt.Println(html)27}28import (29func main() {30 browser := rod.New().ControlURL(launcher.New().MustLaunch()).MustConnect()31 html, err := page.HTML()32 if err != nil {33 log.Fatal(err
MustPage
Using AI Code Generation
1import (2func main() {3 url := launcher.New().MustLaunch()4 defer launcher.New().Kill()5 browser := rod.New().ControlURL(url).MustConnect()6 defer browser.MustClose()7 defer page.MustClose()8 page.MustWaitLoad()9}10import (11func main() {12 url := launcher.New().MustLaunch()13 defer launcher.New().Kill()14 browser := rod.New().ControlURL(url).MustConnect()15 defer browser.MustClose()16 defer page.MustClose()17 page.MustWaitLoad()18 page.MustElement("#lst-ib").MustInput("rod").MustPress(input.Enter)19}20import (21func main() {22 url := launcher.New().MustLaunch()23 defer launcher.New().Kill()24 browser := rod.New().ControlURL(url).MustConnect()25 defer browser.MustClose()26 defer page.MustClose()27 page.MustWaitLoad()28 page.MustElement("#lst-ib").MustInput("rod").MustPress(input.Enter)29 page.MustWaitLoad()
MustPage
Using AI Code Generation
1import (2func main() {3 browser := rod.New().MustConnect()4 page.MustElement("a").MustClick()5 browser.MustClose()6}7import (8func main() {9 browser := rod.New().MustConnect()10 page.MustElement("a").MustClick()11 browser.MustClose()12}13import (14func main() {15 browser := rod.New().MustConnect()16 page.MustElementR("a", "text=Explore").MustClick()17 browser.MustClose()18}19import (20func main() {21 browser := rod.New().MustConnect()22 page.MustElementX("/html/body/div[4]/main/div/div[2]/div/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/h1/a").MustClick()23 browser.MustClose()24}25import (26func main() {27 browser := rod.New().MustConnect()
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!