HTML解析库goquery.zip

时间:2022-08-08 02:12:21
【文件属性】:
文件名称:HTML解析库goquery.zip
文件大小:122KB
文件格式:ZIP
更新时间:2022-08-08 02:12:21
开源项目 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
【文件预览】:
goquery-master
----go.mod(144B)
----.gitattributes(29B)
----example_test.go(2KB)
----filter_test.go(5KB)
----iteration.go(1KB)
----testdata()
--------page3.html(756B)
--------metalreview.html(40KB)
--------gowiki.html(125KB)
--------gotesting.html(21KB)
--------page2.html(747B)
--------page.html(5KB)
----expand.go(3KB)
----iteration_test.go(2KB)
----bench_property_test.go(763B)
----type.go(4KB)
----bench_array_test.go(2KB)
----go.sum(495B)
----array_test.go(5KB)
----type_test.go(4KB)
----utilities_test.go(3KB)
----bench()
--------v0.2.0(19KB)
--------v1.0.0-go1.7(8KB)
--------v0.3.2-go1.2rc1(20KB)
--------v1.0.1c-go1.7(9KB)
--------v0.2.1-go1.1rc1(20KB)
--------v1.0.1b-go1.7(8KB)
--------v0.3.0(20KB)
--------v0.3.2-go1.2(20KB)
--------v0.3.2-go1.2-take2(20KB)
--------v0.1.0(18KB)
--------v1.0.1a-go1.7(8KB)
--------v0.2.0-v0.2.1-go1.1rc1.svg(22KB)
--------v0.1.1(18KB)
--------v0.1.1-v0.2.1-go1.1rc1.svg(21KB)
----expand_test.go(3KB)
----traversal.go(28KB)
----filter.go(6KB)
----doc()
--------tips.md(2KB)
----bench_expand_test.go(2KB)
----manipulation.go(18KB)
----.travis.yml(163B)
----query.go(2KB)
----LICENSE(1KB)
----doc.go(5KB)
----bench_traversal_test.go(14KB)
----README.md(12KB)
----bench_iteration_test.go(959B)
----array.go(4KB)
----bench_query_test.go(2KB)
----bench_example_test.go(922B)
----property.go(6KB)
----misc()
--------git()
----.gitignore(151B)
----utilities.go(5KB)
----query_test.go(2KB)
----manipulation_test.go(13KB)
----bench_filter_test.go(4KB)
----traversal_test.go(20KB)
----property_test.go(6KB)

网友评论