goquery 介绍
goquery是一个使用go语言写成的HTML解析库,可以让你像jQuery那样的方式来操作DOM文档。下面是示例:
func ExampleScrape_MetalReview() { // Load the HTML document (in real use, the type would be *goquery.Document) var doc *Document var e error if doc, e = NewDocument("http://metalreview.com"); e != nil { panic(e.Error()) } // Find the review items (the type of the Selection would be *goquery.Selection) doc.Find(".slider-row:nth-child(1) .slider-item").Each(func(i int, s *Selection) { var band, title string var score float64 // For each item found, get the band, title and score, and print it band = s.Find("strong").Text() title = s.Find("em").Text() if score, e = strconv.ParseFloat(s.Find(".score").Text(), 64); e != nil { // Not a valid float, ignore score fmt.Printf("Review %d: %s - %s.\n", i, band, title) } else { // Print all, including score fmt.Printf("Review %d: %s - %s (%2.1f).\n", i, band, title, score) } })
goquery 官网
https://github.com/PuerkitoBio/goquery
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。