Documentation ¶
Overview ¶
Example ¶
Example demonstrates a technique for getting the top 3 language views per day in Wikipedia.
package main import ( "fmt" "log" "net/http" "github.com/Hunsin/go-htmlutil/dom" ) func main() { req, err := http.NewRequest(http.MethodGet, "https://www.wikipedia.org", nil) if err != nil { log.Fatalln(err) } doc, err := dom.Fetch(req) if err != nil { log.Fatalln(err) } top3 := doc.GetElementsByClassName("central-featured-lang")[:3] for _, elm := range top3 { lang := elm.GetElementsByTagName("strong")[0].TextContent() link := elm.FirstElementChild().GetAttribute("href") fmt.Println(lang, link) } }
Output: English //en.wikipedia.org/ 日本語 //ja.wikipedia.org/ Español //es.wikipedia.org/
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Document ¶
type Document interface { Node Body() Element Children() []Element GetElementByID(id string) Element GetElementsByClassName(string) []Element GetElementsByName(string) []Element GetElementsByTagName(string) []Element Head() Element Links() []Element Title() string }
A Document represents the DOM Document interface, which is the entry point a web page's content.
type Element ¶
type Element interface { Node Children() []Element ClassList() []string ClassName() string FirstElementChild() Element GetAttribute(string) string GetElementsByClassName(string) []Element GetElementsByTagName(string) []Element ID() string LastElementChild() Element NextElementSibling() Element ParentElement() Element PreviousElementSibling() Element TagName() string }
An Element represents the DOM Element interface.
Click to show internal directories.
Click to hide internal directories.