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

->eq() should return a Selection if it's followed by something else? #1

Open
rjp opened this issue Oct 22, 2020 · 1 comment
Open

Comments

@rjp
Copy link

rjp commented Oct 22, 2020

type Item struct {
       Title       string `pagser:"td->eq(0)"`
       Image       string `pagser:"td a img->attr(src)"`
       Quote       string `pagser:"td->eq(3)"`
       Description string `pagser:"td->eq(4)"`
}

If I put td->eq(2) in the tag for Image, I get the text() for the full tr. But without the ->eq(2), it's possible I may end up with a different image. Ideally don't want to make a sub-struct just for this one field if possible.

(Happy to have a go at implementing this if it's actually possible.)

@foolin
Copy link
Owner

foolin commented Oct 23, 2020

Sorry, you can define function():


type Item struct {
       Image       string `pagser:"td->ImgAttr()"`
}

func (i Item) ImgAttr(node *goquery.Selection, args ...string) (out interface{}, err error) {
	return node.Eq(2).Find("img").AttrOr("src", ""), nil
}

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