()
| 83 | } |
| 84 | |
| 85 | func ExampleSingle() { |
| 86 | html := ` |
| 87 | <html> |
| 88 | <body> |
| 89 | <div>1</div> |
| 90 | <div>2</div> |
| 91 | <div>3</div> |
| 92 | </body> |
| 93 | </html> |
| 94 | ` |
| 95 | doc, err := goquery.NewDocumentFromReader(strings.NewReader(html)) |
| 96 | if err != nil { |
| 97 | log.Fatal(err) |
| 98 | } |
| 99 | |
| 100 | // By default, the selector string selects all matching nodes |
| 101 | multiSel := doc.Find("div") |
| 102 | fmt.Println(multiSel.Text()) |
| 103 | |
| 104 | // Using goquery.Single, only the first match is selected |
| 105 | singleSel := doc.FindMatcher(goquery.Single("div")) |
| 106 | fmt.Println(singleSel.Text()) |
| 107 | |
| 108 | // Output: |
| 109 | // 123 |
| 110 | // 1 |
| 111 | } |
| 112 | |
| 113 | // This example shows how to use the goquery.Text function to extract clean, |
| 114 | // human-readable text from a selection, similar to BeautifulSoup's get_text. |
nothing calls this directly
no test coverage detected