aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/PuerkitoBio/goquery/example_test.go
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <fred@miniflux.net> 2017-11-19 21:10:04 -0800
committerGravatar Frédéric Guillot <fred@miniflux.net> 2017-11-19 22:01:46 -0800
commit8ffb773f43c8dc54801ca1d111854e7e881c93c9 (patch)
tree38133a2fc612597a75fed1d13e5b4042f58a2b7e /vendor/github.com/PuerkitoBio/goquery/example_test.go
downloadv2-8ffb773f43c8dc54801ca1d111854e7e881c93c9.tar.gz
v2-8ffb773f43c8dc54801ca1d111854e7e881c93c9.tar.zst
v2-8ffb773f43c8dc54801ca1d111854e7e881c93c9.zip
First commit
Diffstat (limited to 'vendor/github.com/PuerkitoBio/goquery/example_test.go')
-rw-r--r--vendor/github.com/PuerkitoBio/goquery/example_test.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/vendor/github.com/PuerkitoBio/goquery/example_test.go b/vendor/github.com/PuerkitoBio/goquery/example_test.go
new file mode 100644
index 00000000..17b2354d
--- /dev/null
+++ b/vendor/github.com/PuerkitoBio/goquery/example_test.go
@@ -0,0 +1,30 @@
+package goquery_test
+
+import (
+ "fmt"
+ "log"
+
+ "github.com/PuerkitoBio/goquery"
+)
+
+// This example scrapes the reviews shown on the home page of metalsucks.net.
+func Example() {
+ // Load the HTML document
+ 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)
+ })
+ // To see the output of the Example while running the test suite (go test), simply
+ // remove the leading "x" before Output on the next line. This will cause the
+ // example to fail (all the "real" tests should pass).
+
+ // xOutput: voluntarily fail the Example output.
+}