MCPcopy
hub / github.com/andeya/pholcus / Example

Function Example

common/goquery/example_test.go:11–31  ·  view source on GitHub ↗

This example scrapes the reviews shown on the home page of metalsucks.net.

()

Source from the content-addressed store, hash-verified

9
10// This example scrapes the reviews shown on the home page of metalsucks.net.
11func Example() {
12 // Load the HTML document
13 r := goquery.NewDocument("http://metalsucks.net")
14 if r.IsErr() {
15 log.Fatal(r.UnwrapErr())
16 }
17 doc := r.Unwrap()
18
19 // Find the review items
20 doc.Find(".sidebar-reviews article .content-block").Each(func(i int, s *goquery.Selection) {
21 // For each item found, get the band and title
22 band := s.Find("a").Text()
23 title := s.Find("i").Text()
24 fmt.Printf("Review %d: %s - %s\n", i, band, title)
25 })
26 // To see the output of the Example while running the test suite (go test), simply
27 // remove the leading "x" before Output on the next line. This will cause the
28 // example to fail (all the "real" tests should pass).
29
30 // xOutput: voluntarily fail the Example output.
31}

Callers

nothing calls this directly

Calls 5

NewDocumentFunction · 0.92
UnwrapMethod · 0.80
EachMethod · 0.80
TextMethod · 0.80
FindMethod · 0.65

Tested by

no test coverage detected