mgdm / htmlq

Like jq, but for HTML.
MIT License
7k stars 107 forks source link

Can select element by id/class, but not by children's classes #35

Open danimesq opened 2 years ago

danimesq commented 2 years ago

curl --silent https://www.rust-lang.org/ | htmlq '#get-help.languages' returns empty.

Related to: https://github.com/mgdm/htmlq/issues/34

mgdm commented 2 years ago

Hmm, interesting! I noticed it works if I do curl --silent https://www.rust-lang.org/ | htmlq '#get-help.languages' (with a space in between the two parts of the selector). I'll look further.

Mitsunee commented 2 years ago

Seems to be a user error. The element with the id get-help does not have the class languages:

<div class="flex flex-column mw8 w-100 measure-wide-l pv2 pv5-m pv2-ns ph4-m ph4-l" id="get-help">

The selector #get-help.languages thus cannot possibly find any valid result. To get the child with the class languages you would need at least a space like #get-help .languages or using any of the common combinators such as > for direct children (see Combinators on MDN)

Same goes for #34, which also does the same mistake (but in a completely unneeded fashion, an id is already good enough of a selector to find one specific element, specifying the selector by adding the id of a parent has no use unless your goal is to spam-open issues to "irritate" developers (see OP's profile description) by using CSS wrong and claiming it to be a bug).