You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
858 B

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