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 check an object exist or not #27

Open
Eghbalii opened this issue Apr 28, 2020 · 3 comments
Open

How check an object exist or not #27

Eghbalii opened this issue Apr 28, 2020 · 3 comments
Labels

Comments

@Eghbalii
Copy link

Eghbalii commented Apr 28, 2020

I have problem with this example code:
htmlquery.Find(doc, //tbody/tr//td/div[1]/@title)
and get this error:
invalid memory address or nil pointer dereference....
which is true, but I want to manage it to not stop the process and just ignore and pass through it. or before check for find be sure that is exist.
any solution?

@zhengchun
Copy link
Contributor

zhengchun commented Apr 28, 2020

What is version of your htmlquery and xpath package? //tbody/tr//td/div[1]/@title expression won't panic an error even not found any matching node by the expression. I guess your variable doc is nil. or list your example code to test.

@Eghbalii
Copy link
Author

I try to parse some pages.someone are completely ok but some of them haven't div tag in td and that's where I want to solve it. actually i remove [0] and check the length of result. but I interested to know if there is another way.
thanks for your quick answer and this great package.

@zhengchun
Copy link
Contributor

Try this method: QueryAll, It will return error if they got an error. https://godoc.org/github.com/antchfx/htmlquery#QueryAll

But your example is strange, htmlquery won't throw nil pointer dereference error event no matching node, like you talked. //tbody/tr//td/div[1]/@title was passed on my local test.

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

No branches or pull requests

3 participants
@zhengchun @Eghbalii and others