-
Notifications
You must be signed in to change notification settings - Fork 115
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
Support selecting by element's inner text/content #55
Comments
I highly support the idea of selecting elements based on their content. While it is true that Acutally, |
Agree. I'm kind of doubtful that a widely used package like From the developer behind
Later on,
Wonder if Also, for reference, the full list of selectors that |
If it's too hard to get this functionality implemented upstream as a pseudo-class selector, then we could alternatively add a CLI option instead:
I'm suggesting |
Drafted a change as proposed above. Given the following HTML sample from https://lethain.com/company-team-self/: <li class="mb2">
<a href="/work-hard-work-smart/">
Work hard / work smart.</a>
</li>
<li class="mb2">
<a href="/mailbag-not-measurable-whether-hire-exec/"> 👈
Mailbag: What isn't measurable? To hire as exec or not?</a>
</li>
<li class="mb2">
<a href="/reminiscing/">
Reminiscing: the retreat to comforting work.</a>
</li> You can find the hyperlink list item curl -s https://lethain.com/company-team-self/ |
htmlq -c '(?i)mailbag.*measure?' -a href -b https://example.com 'li.mb2 > a'
https://example.com/mailbag-not-measurable-whether-hire-exec/ |
Love
htmlq
—use it daily. Thanks for the effort you've put into this tool.I have a pretty frequent need to find an element based on the text that it contains. For example, I'd like to match on the first
div
(i.e., the one containingItem 1
).There have been various attempts at updating the official CSS specification to support this kind of functionality, though I don't think any of them have actually made their way into the spec. Instead, various tools (Playwright. etc.) extend their own CSS selectors to support one of the following forms.
It would be very useful if I could use the following CSS selector with
htmlq
to match on the previously noted element.htmlq 'div:contains("Item 1")'
To my understanding,
htmlq
relies onkuchiki
for HTML parsing, which in turn relies onservo
for CSS selection—so I think I'd need to request support for this upstream inservo
. Does that seem right to you? Just wanted to run this idea past you in case you've thought about it already and/or have an opinion about it.The text was updated successfully, but these errors were encountered: