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

Case-insensitive CSS attribute selectors support #139

Open
ounissi-zakaria opened this issue Mar 12, 2023 · 1 comment
Open

Case-insensitive CSS attribute selectors support #139

ounissi-zakaria opened this issue Mar 12, 2023 · 1 comment

Comments

@ounissi-zakaria
Copy link

Hello,
Is it possible to add support for Case-insensitive CSS attribute selectors the feature has been available for a while for browsers and i have used it with selenium before but using parsel/scrapy i get an error. Here's a basic example:

>>> from parsel import Selector
>>> selector = Selector(text="""
     <a href="HTTP://SCRAPY.ORG">Link 1</a>
    <a href="http://scrapy.org">Link 2</a>
""")
>>> selector.css('a[href*="http" i]') # should get both a tags
Traceback (most recent call last):

  File ~/miniconda3/envs/DIS/lib/python3.10/site-packages/IPython/core/interactiveshell.py:3442 in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  Cell In[127], line 1
    selector.css('a[href*="http" i]')

  File ~/miniconda3/envs/DIS/lib/python3.10/site-packages/parsel/selector.py:456 in css
    return self.xpath(self._css2xpath(query))

  File ~/miniconda3/envs/DIS/lib/python3.10/site-packages/parsel/selector.py:459 in _css2xpath
    return self._csstranslator.css_to_xpath(query)

  File ~/miniconda3/envs/DIS/lib/python3.10/site-packages/parsel/csstranslator.py:104 in css_to_xpath
    return super().css_to_xpath(css, prefix)

  File ~/miniconda3/envs/DIS/lib/python3.10/site-packages/cssselect/xpath.py:224 in css_to_xpath
    for selector in parse(css)

  File ~/miniconda3/envs/DIS/lib/python3.10/site-packages/cssselect/parser.py:543 in parse
    return list(parse_selector_group(stream))

  File ~/miniconda3/envs/DIS/lib/python3.10/site-packages/cssselect/parser.py:558 in parse_selector_group
    yield Selector(*parse_selector(stream))

  File ~/miniconda3/envs/DIS/lib/python3.10/site-packages/cssselect/parser.py:567 in parse_selector
    result, pseudo_element = parse_simple_selector(stream)

  File ~/miniconda3/envs/DIS/lib/python3.10/site-packages/cssselect/parser.py:634 in parse_simple_selector
    result = parse_attrib(result, stream)

  File ~/miniconda3/envs/DIS/lib/python3.10/site-packages/cssselect/parser.py:802 in parse_attrib
    raise SelectorSyntaxError("Expected ']', got %s" % (next,))

  File <string>
SelectorSyntaxError: Expected ']', got <IDENT 'i' at 15>
@wRAR wRAR transferred this issue from scrapy/parsel Mar 13, 2023
@wRAR
Copy link
Member

wRAR commented Mar 13, 2023

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

No branches or pull requests

2 participants