This example scrapes the reviews shown on the home page of metalsucks.net.
()
| 9 | |
| 10 | // This example scrapes the reviews shown on the home page of metalsucks.net. |
| 11 | func 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 | } |
nothing calls this directly
no test coverage detected