diff --git a/README.md b/README.md index 09cad80..df5ade6 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ Please note that Cascadia's selectors do not necessarily match all supported sel See some tips and tricks in the [wiki][]. -Taken (and adapted as if executed from outside the goquery package) from example_test.go: +Adapted from example_test.go: ```Go package main diff --git a/example_test.go b/example_test.go index 9e8c3c5..1698a2d 100644 --- a/example_test.go +++ b/example_test.go @@ -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() diff --git a/type_test.go b/type_test.go index 98ee3a6..ec32272 100644 --- a/type_test.go +++ b/type_test.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "os" + "strings" "testing" "golang.org/x/net/html" @@ -190,3 +191,15 @@ func TestNewDocumentFromResponseNil(t *testing.T) { t.Error("Expected error, got none") } } + +func TestIssue103(t *testing.T) { + d, err := NewDocumentFromReader(strings.NewReader("