selectolax icon indicating copy to clipboard operation
selectolax copied to clipboard

Tags out of order in returned list when using css to specify multiple tags

Open pushshift opened this issue 1 year ago • 3 comments

When using css selection, I want to grab two different tags (p and h3). When I use the selector like this:

html.css("p,h3")

It selects the appropriate tags but the list gives all p tags first and the h3 tag last.

Example:

<p>   1 </p>
<h3>  2 </h3>
<p>   3 </p>

I would expect the returned list to give: [<node p>, <node h3>, <node p>]

Instead it returns: [<node p>, <node p>, <node h3>]

However, if I use html.css("*") it does return them in correct order but I have to loop through and throw out all unneeded nodes.

If this is indeed a bug, I'd give it a low priority since using css("*") is an alternative where I can simply loop through and only grab what I'm interested in. I just wasn't sure if this was a bug or expected behavior.

If this is expected behavior when selecting multiple css elements, is there a way to get them in the order they appear in the parent (similar to "*" as the CSS selector)

Also, please provide Patreon or Bitcoin wallet if possible so I can contribute for your time. Thank you for creating such an amazing tool. I use this often since it is lightweight, efficient and easy to use.

pushshift avatar Nov 11 '23 15:11 pushshift

Yeah, that's indeed unexpected behavior. I will have a look a bit closer this week.

@lexborisov is there a way to fix this? It looks like both modest and lexbor are affected.

Also, please provide Patreon or Bitcoin wallet if possible so I can contribute for your time. Thank you for creating such an amazing tool. I use this often since it is lightweight, efficient and easy to use.

That would be unfair to take all the credit for this library since most of the hard work is done by @lexborisov. @lexborisov do you accept donations?

rushter avatar Nov 15 '23 11:11 rushter

Hi @rushter @pushshift

Yeah, that's indeed unexpected behavior. I will have a look a bit closer this week.

@lexborisov is there a way to fix this? It looks like both modest and lexbor are affected.

Yeah, it's my fault. I'll try to fix it by Monday.

Also, please provide Patreon or Bitcoin wallet if possible so I can contribute for your time. Thank you for creating such an amazing tool. I use this often since it is lightweight, efficient and easy to use.

That would be unfair to take all the credit for this library since most of the hard work is done by @lexborisov. @lexborisov do you accept donations?

I seriously hadn't considered accepting donations. It doesn't seem to make sense. Not that many people will be donating. @rushter you can safely accept donations. It's your binging and people like it. I don't see anything wrong with it.

lexborisov avatar Nov 15 '23 14:11 lexborisov

@pushshift @rushter

Sorry, I remember this challenge. A lot of things to do at my day job. I hope to solve it soon.

lexborisov avatar Dec 03 '23 20:12 lexborisov

@rushter @pushshift

Sorry, it took time and a complete rewrite of the algorithm. Fixed in https://github.com/lexbor/lexbor/commit/7ed557d53e2b4391a49fb3ea8966177adc652cf0

lexborisov avatar Feb 08 '24 18:02 lexborisov

I've deployed a new release with updated lexbor backend.

rushter avatar Feb 11 '24 07:02 rushter