MCPcopy Create free account
hub / github.com/PuerkitoBio/goquery / ExampleNewDocumentFromReader_string

Function ExampleNewDocumentFromReader_string

example_test.go:63–83  ·  view source on GitHub ↗

This example shows how to use NewDocumentFromReader from a string.

()

Source from the content-addressed store, hash-verified

61
62// This example shows how to use NewDocumentFromReader from a string.
63func ExampleNewDocumentFromReader_string() {
64 // create from a string
65 data := `
66<html>
67 <head>
68 <title>My document</title>
69 </head>
70 <body>
71 <h1>Header</h1>
72 </body>
73</html>`
74
75 doc, err := goquery.NewDocumentFromReader(strings.NewReader(data))
76 if err != nil {
77 log.Fatal(err)
78 }
79 header := doc.Find("h1").Text()
80 fmt.Println(header)
81
82 // Output: Header
83}
84
85func ExampleSingle() {
86 html := `

Callers

nothing calls this directly

Calls 3

NewDocumentFromReaderFunction · 0.92
TextMethod · 0.80
FindMethod · 0.80

Tested by

no test coverage detected