Load HTML documents from different sources
masterYou can load HTML documents into a doc object using several methods depending on your source:
- From a URL: Use
htmlquery.LoadURL(url). - From a local file: Use
htmlquery.LoadDoc(filePath). - From a string: Use
htmlquery.Parse(reader)where the reader is astrings.NewReadercontaining your HTML string.
// Load from URL
doc, err := htmlquery.LoadURL("http://example.com/")
// Load from file
filePath := "/home/user/sample.html"
doc, err := htmlquery.LoadDoc(filePath)
// Load from string
s := "<html>...</html>"
doc, err := htmlquery.Parse(strings.NewReader(s))