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 by a property? #5

Open
shubik opened this issue Dec 23, 2015 · 5 comments
Open

How to select by a property? #5

shubik opened this issue Dec 23, 2015 · 5 comments

Comments

@shubik
Copy link

shubik commented Dec 23, 2015

Thanks for making this package. It does work easily using selectors but I don't understand what's a simple way to select a node by node name and attribute (jQuery style), e.g.

<meta property="og:title" content="Apple iPad mini 4 128Gb WiFi+4G Gold (MK782)">

I tried parsed.querySelectorAll('meta[property="og:title"]') but it retuens empty result.

@ashi009
Copy link
Owner

ashi009 commented Dec 24, 2015

Property selector is not supported, as it will affect performance dramatically.

Note: only tagName, #id, .class selectors supported. And not behave the same as standard querySelectorAll() as it will stop searching sub tree after find a match.

@shubik
Copy link
Author

shubik commented Dec 25, 2015

Thanks for reply. I think it would not be bad even if it was affecting performance (optional use -- optional performance decrease).
Anyway, I picked https://github.com/cheeriojs/cheerio as it does support properties.

@lucaswxp
Copy link

+1, I have several use cases where attribute query is not required, but there are a few which I really need, making it optional seems good to me.

@ashi009
Copy link
Owner

ashi009 commented Sep 25, 2016

It's possible to write a custom query function. The main reason for not supporting this natively is that this requires parsing attributes before querying, which slows everything down, and there are many different matching methods for attributes (eg. ~= and ^=).

@taoqf
Copy link

taoqf commented Jun 13, 2017

I do agree with @ashi009 . but sometimes we indeed need the attribute query, i suggest maybe we could parse some attibutes user given when they call the parse method, not all the attributes. == and != will be good for me. If people do not care about the time the parsing method taken, just use cheerio will be fine.

iamabubakar pushed a commit to iamabubakar/node-fast-html-parser that referenced this issue Sep 8, 2020
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

4 participants