Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Support complex selector in not #124

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

Draft
annbgn wants to merge 17 commits into scrapy:master
base: master
Choose a base branch
Loading
from annbgn:support_complex_selector_in_not

Conversation

@annbgn
Copy link
Contributor

@annbgn annbgn commented Aug 3, 2021
edited
Loading

#51

done: parse complex selector, with any type of combinators (>, +, ~, ), translating to xpath all those combinators according to this comment

this pr also includes code from pr to support :has() pseudo class

annbgn and others added 16 commits June 21, 2021 13:37
Co-authored-by: Eugenio Lacuesta <1731933+elacuesta@users.noreply.github.com>
..._translation_change
Revert xpath translation change to make it consistent
@annbgn annbgn force-pushed the support_complex_selector_in_not branch from d02d89b to 2c15198 Compare August 4, 2021 08:41
Copy link

codecov bot commented Aug 4, 2021
edited
Loading

Codecov Report

Merging #124 (741c0f1) into master (9edc6c3) will increase coverage by 0.62%.
The diff coverage is 99.07%.

❗ Current head 741c0f1 differs from pull request most recent head 3c86499. Consider uploading reports for the commit 3c86499 to get more accurate results
Impacted file tree graph

@@ Coverage Diff @@
## master #124 +/- ##
==========================================
+ Coverage 95.39% 96.01% +0.62% 
==========================================
 Files 3 3 
 Lines 803 904 +101 
 Branches 139 150 +11 
==========================================
+ Hits 766 868 +102 
+ Misses 20 19 -1 
 Partials 17 17 
Impacted Files Coverage Δ
cssselect/xpath.py 95.11% <97.82%> (+0.34%) ⬆️
cssselect/parser.py 96.55% <100.00%> (+0.82%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9edc6c3...3c86499. Read the comment docs.

Copy link
Member

wRAR commented Aug 12, 2021

I've found that at least the Chrome developer console supports this selector, so you can test it on something like:

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>Title</title>
</head>
<body>
 <p>
 <span a="1"></span>
 <span a="2"></span>
 <span a="3"></span>
 </p>
 <div>
 <span a="1"></span>
 </div>
</body>
</html>
annbgn reacted with heart emoji

@annbgn annbgn force-pushed the support_complex_selector_in_not branch from 60a4266 to 90d2eee Compare August 16, 2021 21:31
"*[not([a] and following-sibling::*[b])]"
) # select anything that is not b or doesn't have a sibling a
assert xpath("*:not(a b)") == (
'*[not(name()="b" and ancestor::*[name()="a"])]'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change should also be applied to other 3 combinators.

Copy link
Contributor Author

@annbgn annbgn Aug 17, 2021
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I suppose the tests should look like this:

assert xpath("*:not(a > b)") == '*[not(name()="b" and parent::*[name()="a"])]' # select anything that is not b or doesn't have a parent a
assert xpath("*:not(a + b)") == '*[not(name()="b" and following-sibling::*[position()=1 and name()="a"])]' # select anything that is not b or doesn't have an immediate sibling a
assert xpath("*:not(a ~ b)") == '*[not(name()="b" and following-sibling::*[name()="a"])]' # select anything that is not b or doesn't have a sibling a
assert xpath("*:not(a b)") == '*[not(name()="b" and ancestor::*[name()="a"])]' # select anything that is not b or doesn't have an ancestor a

please correct me if i'm wrong

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's correct.

annbgn reacted with heart emoji
@annbgn annbgn force-pushed the support_complex_selector_in_not branch from 90d2eee to 3c86499 Compare August 17, 2021 19:37
Copy link

@wRAR, is there a chance this will be reviewed soon? Do you need any help?

Copy link
Member

wRAR commented Jun 4, 2025

@mikhainin we don't have specific plans to complete this PR, if you need this feature you can make a new PR based on this one and complete it and we will review it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@wRAR wRAR wRAR left review comments

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /