Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to select an html element based on his text content? #2

Open
sebbbastien opened this issue May 10, 2021 · 1 comment
Open

How to select an html element based on his text content? #2

sebbbastien opened this issue May 10, 2021 · 1 comment

Comments

@sebbbastien
Copy link

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"`
}
@foolin
Copy link
Owner

foolin commented May 10, 2021

  1. You can define a function write your self.
  2. Try the code:
Firstname string `pagser:"h2:contains('Firstname')+p"`

The selector library:
https://github.com/PuerkitoBio/goquery

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants