Skip to content
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

Support complex selector in not #124

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

annbgn
Copy link
Contributor

@annbgn annbgn commented Aug 3, 2021

#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 annbgn force-pushed the support_complex_selector_in_not branch from d02d89b to 2c15198 Compare August 4, 2021 08:41
@codecov
Copy link

codecov bot commented Aug 4, 2021

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.

@wRAR
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 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

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 annbgn force-pushed the support_complex_selector_in_not branch from 90d2eee to 3c86499 Compare August 17, 2021 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants