红联Linux门户
Linux帮助

goquery 1.1.0发布,Go语言的HTML解析器

发布时间:2017-03-12 00:04:48来源:红联作者:uineqa
goquery 1.1.0 发布了,该版本增加了 SetHtml 和 SetText 方法。

goquery是一个使用go语言写成的HTML解析库,可以让你像jQuery那样的方式来操作DOM文档。[code]package main
import (
"fmt"
"log"
"github.com/PuerkitoBio/goquery"
)
func ExampleScrape() {
doc, err := goquery.NewDocument("http://metalsucks.net")
if err != nil {
log.Fatal(err)
}
// Find the review items
doc.Find(".sidebar-reviews article .content-block").Each(func(i int, s *goquery.Selection) {
// For each item found, get the band and title
band := s.Find("a").Text()
title := s.Find("i").Text()
fmt.Printf("Review %d: %s - %s\n", i, band, title)
})
}
func main() {
ExampleScrape()
}[/code]以上为示例代码。

软件详情:https://github.com/PuerkitoBio/goquery

下载地址https://github.com/PuerkitoBio/goquery/releases

来自:开源中国社区
文章评论

共有 0 条评论