antchfx / htmlquery

htmlquery is golang XPath package for HTML query.
https://github.com/antchfx/xpath
MIT License
739 stars 74 forks source link

Code example issue on README #28

Closed otokunaga2 closed 4 years ago

otokunaga2 commented 4 years ago

Hi! Thank you for excellent OSS.

I would like to try this library for my personal project.

However, when I tried to use this library along with README, the following example seemed not working in my environment. So could you share the correct information?

my environment info is as follows

//not worked
list := range htmlquery.Find(doc, "//a/@href")  
for n := range list{
    fmt.Println(htmlquery.InnerText(n)) // output @href value without A element.
}
//=> # command-line-arguments
//./main.go:16:34: cannot use n (type int) as type *html.Node in argument to htmlquery.InnerText

//worked
list := htmlquery.Find(doc, "//a@href")
for _, val := range list{
    fmt.Println(htmlquery.InnerText(val))
}
//=>More information...
zhengchun commented 4 years ago

Sorry, the example about //a/@href is wrong in the README. I will fix it. Thanks for feedback.

list := range htmlquery.Find(doc, "//a/@href")  
for _, node := range list{
    fmt.Println(htmlquery.InnerText(node)) 
}