Closed mhillebrand closed 1 year ago
The css selector starts from the current node, you are basically selecting the main div again.
I'm afraid I don't understand. The current node (ingredients) is <div class="List">
, correct? Why are <p>
tags showing up when I invoke ingredients.css('div')
?
Because that’s how CSS selectors work, you ask for any P tags that are on any level. When you select div, the first match is on the current level, so any elements inside it are ignored and not selected.
On Sun, 15 Oct 2023 at 20:47, mhillebrand @.***> wrote:
I'm afraid I don't understand. The current node (ingredients) is <div class="List">, correct? Why are
tags showing up when I invoke ingredients.css('div')?
— Reply to this email directly, view it on GitHub https://github.com/rushter/selectolax/issues/101#issuecomment-1763444798, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAYKJ332TCZ7O65CBIZQZZTX7QHSJAVCNFSM6AAAAAA57WLSUSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONRTGQ2DINZZHA . You are receiving this because you commented.Message ID: @.***>
In the following code, names[0]
and names2[0]
are identical. I was under the assumption that chaining like lax.css_first('div.List').css('div')
was supported. Is that an incorrect assumption?
lax = HTMLParser(html)
names = lax.css_first('div.List').css('div')
names2 = lax.css('div')
It's supported. The way it works is it includes the current node when executing the css selector. You start at <div class=List>
Bummer. Okay, I guess I just won't use chaining. Thanks.
When parsing the pairs of
<p>
and<div>
tags below, something odd happens. The first<div>
's text erroneously contains the text for all subsequent<div>
tags.Here's what
names
looks like:However, if I change my parsing logic to the following, everything works as expected:
Thoughts?