How to use findOne method of web Package

Best Venom code snippet using web.findOne

model.go

Source:model.go Github

copy

Full Screen

1package ymgal2import (3 "fmt"4 "math/rand"5 "net/url"6 "os"7 "regexp"8 "strconv"9 "sync"10 "time"11 "github.com/antchfx/htmlquery"12 _ "github.com/fumiama/sqlite3" // import sql13 "github.com/jinzhu/gorm"14 log "github.com/sirupsen/logrus"15)16// gdb 得分数据库17var gdb *ymgaldb18// ymgaldb galgame图片数据库19type ymgaldb gorm.DB20var mu sync.RWMutex21// ymgal gal图片储存结构体22type ymgal struct {23 ID int64 `gorm:"column:id" `24 Title string `gorm:"column:title" `25 PictureType string `gorm:"column:picture_type" `26 PictureDescription string `gorm:"column:picture_description;type:varchar(1024)" `27 PictureList string `gorm:"column:picture_list;type:varchar(20000)" `28}29// TableName ...30func (ymgal) TableName() string {31 return "ymgal"32}33// initialize 初始化ymgaldb数据库34func initialize(dbpath string) *ymgaldb {35 var err error36 if _, err = os.Stat(dbpath); err != nil || os.IsNotExist(err) {37 // 生成文件38 f, err := os.Create(dbpath)39 if err != nil {40 return nil41 }42 defer f.Close()43 }44 gdb, err := gorm.Open("sqlite3", dbpath)45 if err != nil {46 panic(err)47 }48 gdb.AutoMigrate(&ymgal{})49 return (*ymgaldb)(gdb)50}51func (gdb *ymgaldb) insertOrUpdateYmgalByID(id int64, title, pictureType, pictureDescription, pictureList string) (err error) {52 db := (*gorm.DB)(gdb)53 y := ymgal{54 ID: id,55 Title: title,56 PictureType: pictureType,57 PictureDescription: pictureDescription,58 PictureList: pictureList,59 }60 if err = db.Debug().Model(&ymgal{}).First(&y, "id = ? ", id).Error; err != nil {61 if gorm.IsRecordNotFoundError(err) {62 err = db.Debug().Model(&ymgal{}).Create(&y).Error // newUser not user63 }64 } else {65 err = db.Debug().Model(&ymgal{}).Where("id = ? ", id).Update(map[string]interface{}{66 "title": title,67 "picture_type": pictureType,68 "picture_description": pictureDescription,69 "picture_list": pictureList,70 }).Error71 }72 return73}74func (gdb *ymgaldb) getYmgalByID(id string) (y ymgal) {75 db := (*gorm.DB)(gdb)76 db.Debug().Model(&ymgal{}).Where("id = ?", id).Take(&y)77 return78}79func (gdb *ymgaldb) randomYmgal(pictureType string) (y ymgal) {80 db := (*gorm.DB)(gdb)81 var count int82 s := db.Debug().Model(&ymgal{}).Where("picture_type = ?", pictureType).Count(&count)83 if count == 0 {84 return85 }86 s.Offset(rand.Intn(count)).Take(&y)87 return88}89func (gdb *ymgaldb) getYmgalByKey(pictureType, key string) (y ymgal) {90 db := (*gorm.DB)(gdb)91 var count int92 s := db.Debug().Model(&ymgal{}).Where("picture_type = ? and (picture_description like ? or title like ?) ", pictureType, "%"+key+"%", "%"+key+"%").Count(&count)93 if count == 0 {94 return95 }96 s.Offset(rand.Intn(count)).Take(&y)97 return98}99const (100 webURL = "https://www.ymgal.com"101 cgType = "Gal CG"102 emoticonType = "其他"103 webPicURL = webURL + "/co/picset/"104 reNumber = `\d+`105)106var (107 cgURL = webURL + "/search?type=picset&sort=default&category=" + url.QueryEscape(cgType) + "&page="108 emoticonURL = webURL + "/search?type=picset&sort=default&category=" + url.QueryEscape(emoticonType) + "&page="109 commonPageNumberExpr = "//*[@id='pager-box']/div/a[@class='icon item pager-next']/preceding-sibling::a[1]/text()"110 cgIDList []string111 emoticonIDList []string112)113func initPageNumber() (maxCgPageNumber, maxEmoticonPageNumber int) {114 doc, err := htmlquery.LoadURL(cgURL + "1")115 if err != nil {116 log.Errorln("[ymgal]:", err)117 }118 maxCgPageNumber, err = strconv.Atoi(htmlquery.FindOne(doc, commonPageNumberExpr).Data)119 if err != nil {120 log.Errorln("[ymgal]:", err)121 }122 doc, err = htmlquery.LoadURL(emoticonURL + "1")123 if err != nil {124 log.Errorln("[ymgal]:", err)125 }126 maxEmoticonPageNumber, err = strconv.Atoi(htmlquery.FindOne(doc, commonPageNumberExpr).Data)127 if err != nil {128 log.Errorln("[ymgal]:", err)129 }130 return131}132func getPicID(pageNumber int, pictureType string) {133 var picURL string134 if pictureType == cgType {135 picURL = cgURL + strconv.Itoa(pageNumber)136 } else if pictureType == emoticonType {137 picURL = emoticonURL + strconv.Itoa(pageNumber)138 }139 doc, err := htmlquery.LoadURL(picURL)140 if err != nil {141 log.Errorln("[ymgal]:", err)142 }143 list := htmlquery.Find(doc, "//*[@id='picset-result-list']/ul/div/div[1]/a")144 for i := 0; i < len(list); i++ {145 re := regexp.MustCompile(reNumber)146 picID := re.FindString(list[i].Attr[0].Val)147 if pictureType == cgType {148 cgIDList = append(cgIDList, picID)149 } else if pictureType == emoticonType {150 emoticonIDList = append(emoticonIDList, picID)151 }152 }153}154func updatePic() {155 maxCgPageNumber, maxEmoticonPageNumber := initPageNumber()156 for i := 1; i <= maxCgPageNumber; i++ {157 getPicID(i, cgType)158 time.Sleep(time.Millisecond * 500)159 }160 for i := 1; i <= maxEmoticonPageNumber; i++ {161 getPicID(i, emoticonType)162 time.Sleep(time.Millisecond * 500)163 }164CGLOOP:165 for i := len(cgIDList) - 1; i >= 0; i-- {166 mu.RLock()167 y := gdb.getYmgalByID(cgIDList[i])168 mu.RUnlock()169 if y.PictureList == "" {170 mu.Lock()171 storeCgPic(cgIDList[i])172 mu.Unlock()173 } else {174 break CGLOOP175 }176 time.Sleep(time.Millisecond * 500)177 }178EMOTICONLOOP:179 for i := len(emoticonIDList) - 1; i >= 0; i-- {180 mu.RLock()181 y := gdb.getYmgalByID(emoticonIDList[i])182 mu.RUnlock()183 if y.PictureList == "" {184 mu.Lock()185 storeEmoticonPic(emoticonIDList[i])186 mu.Unlock()187 } else {188 break EMOTICONLOOP189 }190 time.Sleep(time.Millisecond * 500)191 }192}193func storeCgPic(picIDStr string) {194 picID, err := strconv.ParseInt(picIDStr, 10, 64)195 if err != nil {196 log.Errorln("[ymgal]:", err)197 }198 pictureType := cgType199 doc, err := htmlquery.LoadURL(webPicURL + picIDStr)200 if err != nil {201 log.Errorln("[ymgal]:", err)202 }203 title := htmlquery.FindOne(doc, "//meta[@name='name']").Attr[1].Val204 pictureDescription := htmlquery.FindOne(doc, "//meta[@name='description']").Attr[1].Val205 pictureNumberStr := htmlquery.FindOne(doc, "//div[@class='meta-info']/div[@class='meta-right']/span[2]/text()").Data206 re := regexp.MustCompile(reNumber)207 pictureNumber, err := strconv.Atoi(re.FindString(pictureNumberStr))208 if err != nil {209 log.Errorln("[ymgal]:", err)210 }211 pictureList := ""212 for i := 1; i <= pictureNumber; i++ {213 picURL := htmlquery.FindOne(doc, fmt.Sprintf("//*[@id='main-picset-warp']/div/div[2]/div/div[@class='swiper-wrapper']/div[%d]", i)).Attr[1].Val214 if i == 1 {215 pictureList += picURL216 } else {217 pictureList += "," + picURL218 }219 }220 err = gdb.insertOrUpdateYmgalByID(picID, title, pictureType, pictureDescription, pictureList)221 if err != nil {222 log.Errorln("[ymgal]:", err)223 }224}225func storeEmoticonPic(picIDStr string) {226 picID, err := strconv.ParseInt(picIDStr, 10, 64)227 if err != nil {228 log.Errorln("[ymgal]:", err)229 }230 pictureType := emoticonType231 doc, err := htmlquery.LoadURL(webPicURL + picIDStr)232 if err != nil {233 log.Errorln("[ymgal]:", err)234 }235 title := htmlquery.FindOne(doc, "//meta[@name='name']").Attr[1].Val236 pictureDescription := htmlquery.FindOne(doc, "//meta[@name='description']").Attr[1].Val237 pictureNumberStr := htmlquery.FindOne(doc, "//div[@class='meta-info']/div[@class='meta-right']/span[2]/text()").Data238 re := regexp.MustCompile(reNumber)239 pictureNumber, err := strconv.Atoi(re.FindString(pictureNumberStr))240 if err != nil {241 log.Errorln("[ymgal]:", err)242 }243 pictureList := ""244 for i := 1; i <= pictureNumber; i++ {245 picURL := htmlquery.FindOne(doc, fmt.Sprintf("//*[@id='main-picset-warp']/div/div[@class='stream-list']/div[%d]/img", i)).Attr[1].Val246 if i == 1 {247 pictureList += picURL248 } else {249 pictureList += "," + picURL250 }251 }252 err = gdb.insertOrUpdateYmgalByID(picID, title, pictureType, pictureDescription, pictureList)253 if err != nil {254 log.Errorln("[ymgal]:", err)255 }256}...

Full Screen

Full Screen

notegraphutil_test.go

Source:notegraphutil_test.go Github

copy

Full Screen

1package main2import (3 "strings"4 "testing"5 "github.com/antchfx/xmlquery"6 "github.com/antchfx/xpath"7 "github.com/freddy33/graphml"8 "github.com/stretchr/testify/assert"9)10func TestCreateEdges(t *testing.T) {11 noteLinkParser = NewNoteLinkParser("www.evernote.com", "76136038", "s12")12 webNoteLink := noteLinkParser.ParseNoteLink("sourceNoteGUID", *CreateWebLinkURL("targetNoteGUID"), "WebLink")13 edges := NewNoteGraphUtil().CreateEdges([]NoteLink{*webNoteLink})14 assert.Equal(t, webNoteLink.SourceNoteGUID, edges[0].Source)15 assert.Equal(t, webNoteLink.TargetNoteGUID, edges[0].Target)16}17func TestCreateNodes(t *testing.T) {18 webLinkURL := CreateWebLinkURL("GUID")19 note := Note{GUID: "GUID", Title: "Title", Description: "Title", URL: *webLinkURL, URLType: WebLink}20 nodes := NewNoteGraphUtil().CreateNodes([]Note{note})21 assert.Equal(t, note.GUID, nodes[0].ID)22}23func TestConvertNoteGraphLinkedNotes(t *testing.T) {24 // four Notes, valid NoteLinks, disconnected graph25 noteA := Note{GUID: "A", Title: "TitleA", Description: "DescriptionA", URL: *CreateWebLinkURL("A"), URLType: WebLink}26 noteB := Note{GUID: "B", Title: "TitleB", Description: "DescriptionB", URL: *CreateWebLinkURL("B"), URLType: WebLink}27 noteC := Note{GUID: "C", Title: "TitleC", Description: "DescriptionC", URL: *CreateWebLinkURL("C"), URLType: WebLink}28 noteD := Note{GUID: "D", Title: "TitleD", Description: "DescriptionD", URL: *CreateWebLinkURL("D"), URLType: WebLink}29 noteE := Note{GUID: "E", Title: "TitleE", Description: "DescriptionE", URL: *CreateWebLinkURL("E"), URLType: WebLink}30 noteLinkAB := NoteLink{SourceNoteGUID: "A", TargetNoteGUID: "B", URL: *CreateWebLinkURL("B"), URLType: WebLink}31 noteLinkCD := NoteLink{SourceNoteGUID: "C", TargetNoteGUID: "D", URL: *CreateWebLinkURL("D"), URLType: WebLink}32 noteGraph := NewNoteGraph()33 noteGraph.Add(noteA, []NoteLink{noteLinkAB})34 noteGraph.Add(noteB, []NoteLink{})35 noteGraph.Add(noteC, []NoteLink{noteLinkCD})36 noteGraph.Add(noteD, []NoteLink{})37 noteGraph.Add(noteE, []NoteLink{})38 graphMLDocument := NewNoteGraphUtil().ConvertNoteGraph(noteGraph, false)39 encodedGraphMLDocument := EncodeGraphMLDocument(graphMLDocument)40 xmlDocument, err := xmlquery.Parse(strings.NewReader(encodedGraphMLDocument))41 if err != nil {42 panic(err)43 }44 graph := xmlquery.FindOne(xmlDocument, "/graphml/graph")45 assert.Equal(t, NoteGraphID, graph.SelectAttr("id"))46 assert.Equal(t, string(graphml.EdgeDirected), graph.SelectAttr("edgedefault"))47 AssertNodeCount(t, xmlDocument, 4)48 AssertNoteEqualNode(t, xmlDocument, noteA.GUID, noteA.Title, noteA.Description, noteA.URL.String())49 AssertNoteEqualNode(t, xmlDocument, noteB.GUID, noteB.Title, noteB.Description, noteB.URL.String())50 AssertNoteEqualNode(t, xmlDocument, noteC.GUID, noteC.Title, noteC.Description, noteC.URL.String())51 AssertNoteEqualNode(t, xmlDocument, noteD.GUID, noteD.Title, noteD.Description, noteD.URL.String())52 AssertEdgeCount(t, xmlDocument, 2)53 AssertNoteLinkEqualEdge(t, xmlDocument, "1", noteLinkAB.SourceNoteGUID, noteLinkAB.TargetNoteGUID, noteLinkAB.Text, noteLinkAB.Text)54 AssertNoteLinkEqualEdge(t, xmlDocument, "2", noteLinkCD.SourceNoteGUID, noteLinkCD.TargetNoteGUID, noteLinkCD.Text, noteLinkCD.Text)55}56func TestConvertNoteGraphAllNotes(t *testing.T) {57 // four Notes, valid NoteLinks, disconnected graph58 noteA := Note{GUID: "A", Title: "TitleA", Description: "DescriptionA", URL: *CreateWebLinkURL("A"), URLType: WebLink}59 noteB := Note{GUID: "B", Title: "TitleB", Description: "DescriptionB", URL: *CreateWebLinkURL("B"), URLType: WebLink}60 noteC := Note{GUID: "C", Title: "TitleC", Description: "DescriptionC", URL: *CreateWebLinkURL("C"), URLType: WebLink}61 noteD := Note{GUID: "D", Title: "TitleD", Description: "DescriptionD", URL: *CreateWebLinkURL("D"), URLType: WebLink}62 noteE := Note{GUID: "E", Title: "TitleE", Description: "DescriptionE", URL: *CreateWebLinkURL("E"), URLType: WebLink}63 noteLinkAB := NoteLink{SourceNoteGUID: "A", TargetNoteGUID: "B", URL: *CreateWebLinkURL("B"), URLType: WebLink}64 noteLinkCD := NoteLink{SourceNoteGUID: "C", TargetNoteGUID: "D", URL: *CreateWebLinkURL("D"), URLType: WebLink}65 noteGraph := NewNoteGraph()66 noteGraph.Add(noteA, []NoteLink{noteLinkAB})67 noteGraph.Add(noteB, []NoteLink{})68 noteGraph.Add(noteC, []NoteLink{noteLinkCD})69 noteGraph.Add(noteD, []NoteLink{})70 noteGraph.Add(noteE, []NoteLink{})71 graphMLDocument := NewNoteGraphUtil().ConvertNoteGraph(noteGraph, true)72 encodedGraphMLDocument := EncodeGraphMLDocument(graphMLDocument)73 xmlDocument, err := xmlquery.Parse(strings.NewReader(encodedGraphMLDocument))74 if err != nil {75 panic(err)76 }77 graph := xmlquery.FindOne(xmlDocument, "/graphml/graph")78 assert.Equal(t, NoteGraphID, graph.SelectAttr("id"))79 assert.Equal(t, string(graphml.EdgeDirected), graph.SelectAttr("edgedefault"))80 AssertNodeCount(t, xmlDocument, 5)81 AssertNoteEqualNode(t, xmlDocument, noteA.GUID, noteA.Title, noteA.Description, noteA.URL.String())82 AssertNoteEqualNode(t, xmlDocument, noteB.GUID, noteB.Title, noteB.Description, noteB.URL.String())83 AssertNoteEqualNode(t, xmlDocument, noteC.GUID, noteC.Title, noteC.Description, noteC.URL.String())84 AssertNoteEqualNode(t, xmlDocument, noteD.GUID, noteD.Title, noteD.Description, noteD.URL.String())85 AssertNoteEqualNode(t, xmlDocument, noteE.GUID, noteE.Title, noteE.Description, noteE.URL.String())86 AssertEdgeCount(t, xmlDocument, 2)87 AssertNoteLinkEqualEdge(t, xmlDocument, "1", noteLinkAB.SourceNoteGUID, noteLinkAB.TargetNoteGUID, noteLinkAB.Text, noteLinkAB.Text)88 AssertNoteLinkEqualEdge(t, xmlDocument, "2", noteLinkCD.SourceNoteGUID, noteLinkCD.TargetNoteGUID, noteLinkCD.Text, noteLinkCD.Text)89}90func AssertNodeCount(t *testing.T, xmlNode *xmlquery.Node, expectedCount int) {91 expr, err := xpath.Compile("count(//node)")92 if err != nil {93 panic(err)94 }95 actualCount := expr.Evaluate(xmlquery.CreateXPathNavigator(xmlNode)).(float64)96 assert.Equal(t, expectedCount, int(actualCount))97}98func AssertNoteEqualNode(t *testing.T, xmlNode *xmlquery.Node, nodeID, nodeLabel, nodeDescription, nodeURL string) {99 node := xmlquery.FindOne(xmlNode, "/graphml/graph/node[@id='"+nodeID+"']")100 assert.Equal(t, nodeLabel, xmlquery.FindOne(node, "/data[@key='"+NodeLabelID+"']").InnerText())101 assert.Equal(t, nodeDescription, xmlquery.FindOne(node, "/data[@key='"+NodeDescriptionID+"']").InnerText())102 assert.Equal(t, nodeURL, xmlquery.FindOne(node, "/data[@key='"+NodeURLID+"']").InnerText())103}104func AssertEdgeCount(t *testing.T, xmlNode *xmlquery.Node, expectedCount int) {105 expr, err := xpath.Compile("count(//edge)")106 if err != nil {107 panic(err)108 }109 actualCount := expr.Evaluate(xmlquery.CreateXPathNavigator(xmlNode)).(float64)110 assert.Equal(t, expectedCount, int(actualCount))111}112func AssertNoteLinkEqualEdge(t *testing.T, xmlNode *xmlquery.Node, edgeIndex, sourceNodeID, targetNodeID, edgeLabel, edgeDescription string) {113 edge := xmlquery.FindOne(xmlNode, "/graphml/graph/edge["+edgeIndex+"]")114 assert.Equal(t, sourceNodeID, edge.SelectAttr("source"))115 assert.Equal(t, targetNodeID, edge.SelectAttr("target"))116 assert.Equal(t, edgeLabel, xmlquery.FindOne(edge, "/data[@key='"+EdgeLabelID+"']").InnerText())117 assert.Equal(t, edgeDescription, xmlquery.FindOne(edge, "/data[@key='"+EdgeDescriptionID+"']").InnerText())118}...

Full Screen

Full Screen

router.go

Source:router.go Github

copy

Full Screen

...16func Init(service web.Service) {17 service.Handle("/",http.FileServer(http.Dir("views")))18 /*-----------------------seller----------------------------*/19 service.Handle("/seller/search.do",http.HandlerFunc(seller.Search))20 service.Handle("/seller/findOne.do",http.HandlerFunc(seller.FindOne))21 service.Handle("/seller/updateStatus.do",http.HandlerFunc(seller.UpdateStatus))22 /*-----------------------login----------------------------*/23 service.Handle("/login/search.do",http.HandlerFunc(brand.Search))24 service.Handle("/login/save.do",http.HandlerFunc(brand.Save))25 service.Handle("/login/findById.do",http.HandlerFunc(brand.FindById))26 service.Handle("/login/delete.do",http.HandlerFunc(brand.Delete))27 service.Handle("/login/update.do",http.HandlerFunc(brand.Update))28 service.Handle("/login/selectOptionList.do",http.HandlerFunc(brand.SelectOptionList))29 /*-----------------------specification----------------------------*/30 service.Handle("/specification/search.do",http.HandlerFunc(specification.Search))31 service.Handle("/specification/add.do",http.HandlerFunc(specification.Add))32 service.Handle("/specification/delete.do",http.HandlerFunc(specification.Delete))33 service.Handle("/specification/findOne.do",http.HandlerFunc(specification.FindOne))34 service.Handle("/specification/update.do",http.HandlerFunc(specification.Update))35 service.Handle("/specification/selectOptionList.do",http.HandlerFunc(specification.SelectOptionList))36 /*-----------------------typeTemplate----------------------------*/37 service.Handle("/typeTemplate/search.do",http.HandlerFunc(typeTemplate.Search))38 service.Handle("/typeTemplate/add.do",http.HandlerFunc(typeTemplate.Add))39 service.Handle("/typeTemplate/delete.do",http.HandlerFunc(typeTemplate.Delete))40 service.Handle("/typeTemplate/findOne.do",http.HandlerFunc(typeTemplate.FindOne))41 service.Handle("/typeTemplate/update.do",http.HandlerFunc(typeTemplate.Update))42 /*-----------------------itemCat----------------------------*/43 service.Handle("/itemCat/findByParentId.do",http.HandlerFunc(itemCat.FindByParentId))44 service.Handle("/itemCat/findAll.do",http.HandlerFunc(itemCat.FindAll))45 /*-----------------------goods----------------------------*/46 service.Handle("/goods/search.do",http.HandlerFunc(goods.Search))47 service.Handle("/goods/delete.do",http.HandlerFunc(goods.Delete))48 service.Handle("/goods/updateStatus.do",http.HandlerFunc(goods.UpdateStatus))49 /*-----------------------contentCategory----------------------------*/50 service.Handle("/contentCategory/search.do",http.HandlerFunc(contentCategory.Search))51 service.Handle("/contentCategory/add.do",http.HandlerFunc(contentCategory.Add))52 service.Handle("/contentCategory/delete.do",http.HandlerFunc(contentCategory.Delete))53 service.Handle("/contentCategory/findOne.do",http.HandlerFunc(contentCategory.FindOne))54 service.Handle("/contentCategory/findAll.do",http.HandlerFunc(contentCategory.FindAll))55 /*-----------------------content----------------------------*/56 service.Handle("/content/search.do",http.HandlerFunc(content.Search))57 service.Handle("/content/add.do",http.HandlerFunc(content.Add))58 service.Handle("/content/delete.do",http.HandlerFunc(content.Delete))59 service.Handle("/content/findOne.do",http.HandlerFunc(content.FindOne))60 service.Handle("/content/update.do",http.HandlerFunc(content.Update))61 /*-----------------------upload----------------------------*/62 service.Handle("/upload/uploadFile.do",http.HandlerFunc(upload.UploadFile))63 /*-----------------------manager----------------------------*/64 service.Handle("/manager/login",http.HandlerFunc(login.ManagerLogin))65}...

Full Screen

Full Screen

findOne

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 c := colly.NewCollector()4 c.OnHTML("a[href]", func(e *colly.HTMLElement) {5 link := e.Attr("href")6 fmt.Printf("Link found: %q -> %s7 e.Request.Visit(link)8 })9 c.OnRequest(func(r *colly.Request) {10 fmt.Println("Visiting", r.URL)11 })12}13import (14func main() {15 c := colly.NewCollector()16 c.OnHTML("a[href]", func(e *colly.HTMLElement) {17 link := e.Attr("href")18 fmt.Printf("Link found: %q -> %s19 e.Request.Visit(link)20 })21 c.OnRequest(func(r *colly.Request) {22 fmt.Println("Visiting", r.URL)23 })24}25import (26func main() {27 c := colly.NewCollector()28 c.OnHTML("a[href]", func(e *colly.HTMLElement) {29 link := e.Attr("href")30 fmt.Printf("Link found: %q -> %s31 e.Request.Visit(link)32 })33 c.OnRequest(func(r *colly.Request) {34 fmt.Println("Visiting", r.URL)35 })36}37import (38func main() {39 c := colly.NewCollector()40 c.OnHTML("a[href]", func(e *colly.HTMLElement) {41 link := e.Attr("href")42 fmt.Printf("Link found: %q -> %s43 e.Request.Visit(link)44 })45 c.OnRequest(func(r *colly

Full Screen

Full Screen

findOne

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 c := colly.NewCollector()4 c.OnHTML("a[href]", func(e *colly.HTMLElement) {5 link := e.Attr("href")6 fmt.Printf("Link found: %q -> %s7 c.Visit(e.Request.AbsoluteURL(link))8 })9}10import (11func main() {12 c := colly.NewCollector()13 c.OnHTML("a[href]", func(e *colly.HTMLElement) {14 link := e.Attr("href")15 fmt.Printf("Link found: %q -> %s16 c.Visit(e.Request.AbsoluteURL(link))17 })18}19import (20func main() {21 c := colly.NewCollector()22 c.OnHTML("a[href]", func(e *colly.HTMLElement) {23 link := e.Attr("href")24 fmt.Printf("Link found: %q -> %s25 c.Visit(e.Request.AbsoluteURL(link))26 })27}28import (29func main() {30 c := colly.NewCollector()31 c.OnHTML("a[href]", func(e *colly.HTMLElement) {32 link := e.Attr("href")33 fmt.Printf("Link found: %q -> %s34 c.Visit(e.Request.AbsoluteURL(link))35 })36}

Full Screen

Full Screen

findOne

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 driver := agouti.ChromeDriver()4 if err := driver.Start(); err != nil {5 panic(err)6 }7 page, err := driver.NewPage()8 if err != nil {9 panic(err)10 }11 panic(err)12 }13 searchField := page.Find("input[name='q']")14 if err := searchField.Fill("Agouti"); err != nil {15 panic(err)16 }17 if err := page.Find("input[type='submit']").Click(); err != nil {18 panic(err)19 }20 page.Screenshot("screenshot.png")21 fmt.Println("Success")22}23import (24func main() {25 driver := agouti.ChromeDriver()26 if err := driver.Start(); err != nil {27 panic(err)28 }29 page, err := driver.NewPage()30 if err != nil {31 panic(err)32 }33 panic(err)34 }35 searchField := page.Find("input[name='q']")36 if err := searchField.Fill("Agouti"); err != nil {37 panic(err)38 }39 if err := page.Find("input[type='submit']").Click(); err != nil {40 panic(err)41 }42 links, err := page.FindAll("h3").Elements()43 if err != nil {44 panic(err)45 }46 for _, link := range links {47 text, err := link.Text()48 if err != nil {49 panic(err)50 }51 fmt.Println(text)52 }53 page.Screenshot("screenshot.png")54 fmt.Println("Success")55}56import (57func main() {58 driver := agouti.ChromeDriver()59 if err := driver.Start(); err

Full Screen

Full Screen

findOne

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if err != nil {4 panic(err)5 }6 fmt.Println(htmlquery.InnerText(node))7}8import (9func main() {10 if err != nil {11 panic(err)12 }13 for _, node := range nodes {14 fmt.Println(htmlquery.InnerText(node))15 }16}17import (18func main() {19 if err != nil {20 panic(err)21 }22 for _, node := range nodes {23 fmt.Println(htmlquery.InnerText(node))24 }25}26import (27func main() {

Full Screen

Full Screen

findOne

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if err != nil {4 panic(err)5 }6 defer res.Body.Close()7 if res.StatusCode != 200 {8 panic("status code error: " + res.Status)9 }10 doc, err := goquery.NewDocumentFromReader(res.Body)11 if err != nil {12 panic(err)13 }14 doc.Find(".gb_P").Each(func(i int, s *goquery.Selection) {15 band := s.Find("a").Text()16 title := s.Find("a").Text()17 fmt.Printf("Review %d: %s - %s\n", i, band, title)18 })19}

Full Screen

Full Screen

findOne

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 driver := agouti.ChromeDriver()4 driver.Start()5 page, _ := driver.NewPage()6 searchBox := page.FindByName("q")7 searchBox.Fill("Agouti")8 page.FindByName("btnK").Click()9 driver.Stop()10 fmt.Println("Test completed")11}

Full Screen

Full Screen

findOne

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if err != nil {4 log.Fatal(err)5 }6 defer res.Body.Close()7 if res.StatusCode != 200 {8 log.Fatalf("status code error: %d %s", res.StatusCode, res.Status)9 }10 doc, err := goquery.NewDocumentFromReader(res.Body)11 if err != nil {12 log.Fatal(err)13 }14 doc.Find(".review").Each(func(i int, s *goquery.Selection) {15 band := s.Find("a").Text()16 title := s.Find("i").Text()17 fmt.Printf("Review %d: %s - %s\n", i, band, title)18 })19}20import (21func main() {22 if err != nil {23 log.Fatal(err)24 }25 defer res.Body.Close()26 if res.StatusCode != 200 {27 log.Fatalf("status code error: %d %s", res.StatusCode, res.Status)28 }29 doc, err := goquery.NewDocumentFromReader(res.Body)30 if err != nil {31 log.Fatal(err)32 }33 doc.Find(".review").Each(func(i int, s *goquery.Selection) {

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Venom automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful