edit example to follow Go conventions

This commit is contained in:
Martin Angers
2016-04-08 07:39:02 -04:00
parent 4126223a86
commit 5cc721859e
4 changed files with 22 additions and 11 deletions
+7 -9
View File
@@ -1,24 +1,22 @@
package goquery
package goquery_test
import (
"fmt"
"log"
// In real use, this import would be required (not in this example, since it
// is part of the goquery package)
//"github.com/PuerkitoBio/goquery"
"github.com/PuerkitoBio/goquery"
)
// This example scrapes the reviews shown on the home page of metalsucks.net.
func ExampleScrape_MetalSucks() {
// Load the HTML document (in real use, the type would be *goquery.Document)
doc, err := NewDocument("http://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 (the type of the Selection would be *goquery.Selection)
doc.Find(".reviews-wrap article .review-rhs").Each(func(i int, s *Selection) {
// Find the review items
doc.Find(".reviews-wrap article .review-rhs").Each(func(i int, s *goquery.Selection) {
// For each item found, get the band and title
band := s.Find("h3").Text()
title := s.Find("i").Text()