Golang goquery

goquery Address:

https://github.com/PuerkitoBio/goquery

 

Goquery also need to download two packages need to use:

https://github.com/andybalholm/cascadia

https://golang.org\x\net\html

golang.org this is a wall, you can use the mirror:

https://github.com/golang/net

 

An element, ID selection:

import(

   "fmt"

   "log"

   "github.com/PuerkitoBio/goquery"

)

func main(){

   url:="http://www.baidu.com"

   dom,err:=goquery.NewDocument(url)

   if err != nil {

      log.Fatalln(err)

   }

 

   // use the find () function finds the element "div", type ".class" or ID "#id", and use Each loop through all the matches assigned to the selection, 

   dom.Find("div").Each(func(i int, selection *goquery.Selection){

      fmt.Println(selection.Text()) 

   }

}

 

Guess you like

Origin www.cnblogs.com/xsly/p/10990350.html