-
-
Notifications
You must be signed in to change notification settings - Fork 897
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
CSS foo~:nth-child(2)
gives incorrect XPath
#707
Comments
you should not use position() which depends on the context position instead try
and similarly for Xn
|
Thank you @AurelPaulovic , I think that should work. Now for a selector |
Sadly, there is no way how to do that in XPath 1.0. You can't assign any variables and there is no way how to get to the outer context. |
Hi,
I’m the maintainer of cssselect, which does in Python pretty much the same as Nokogiri for CSS selectors: translate them to XPath. It looks like the scrapy/cssselect#12 bug also applies to Nokogiri. Namely, the XPath translation of
or
:nth-child()
and similar pseudo-classes is wrong when used after the~
combinator. Here is a test case:Expected output:
child2 child2
. Actual outputchild2 child3
.The problem is in the XPath translation of the later selector:
//child1/following-sibling::*[position() = 2 and self::*]
gives the element at position 2 when counting from child1, while we want the position among the parent’s children.I am not sure it is even possible to correctly translate this selector to XPath: the
=
XPath operator on node-sets compares the text content of elements, not their identity.The issue is similar for scrapy/cssselect#4 and Nokogiri’s #394.
The text was updated successfully, but these errors were encountered: