Closed fallingin closed 1 year ago
The prefix descendant-or-self:: causes the code base_info_div.css('div:nth-child(2)) actually select base_info_div itself firstly.
Yes, and you could minimize all of this to just base_info_div.css('div')
which also returns base_info_div
because that's a div
. This is clearly by design.
whether it's a feature or a way to deal with some special case or just a bug?
I'm sure it's a design decision. Note that while you quoted a default value in parsel, the cssselect function that it calls has the same default (it's the same function in the base class, after all) and it was there starting with the initial cssselect code in 2007.
Description
This is my first time submitting an issue, so please forgive me if there are any problems. Hoping it helps.
When I use the css selector :nth-child(2) in such an html code structure, I encountered an unexpected code behavior:
Steps to Reproduce
You can reproduce 100% of the phenomenon I described with the following simple code.
Expected behavior:
Actual behavior:
Versions
Additional context
After tracing the code execution, I found that it was the default prefix in the following code causing my problem.
https://github.com/scrapy/parsel/blob/8c39b2fa564295247bc46cd30e313dc449889b12/parsel/csstranslator.py#L147-L152
The prefix
descendant-or-self::
causes the codebase_info_div.css('div:nth-child(2))
actually selectbase_info_div
itself firstly.I've figured out what this prefix does and I'm wondering what the point of the default prefix is, whether it's a feature or a way to deal with some special case or just a bug?