pagser
pagser copied to clipboard
How to select an html element based on his text content?
What should be the selector for this kind of html code:
<h2>Firstname</h2>
<p>John</p>
<!--- some random html code, with random h2 tags -->
<h2>Lastname</h2>
<p>Doe</p>
I would like to fill this struct:
type Person struct {
Firstname string `pagser:"h2[text=Firstname]+p"`
Lastname string `pagser:"h2[text=Lastname]+p"`
}
- You can define a function write your self.
- Try the code:
Firstname string `pagser:"h2:contains('Firstname')+p"`
The selector library: https://github.com/PuerkitoBio/goquery