This example shows how to use NewDocumentFromReader from a string.
()
| 61 | |
| 62 | // This example shows how to use NewDocumentFromReader from a string. |
| 63 | func 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 | |
| 85 | func ExampleSingle() { |
| 86 | html := ` |
nothing calls this directly
no test coverage detected