Skip to content

css selector parser problem #433

Description

@crucifyer

Have you searched if there an existing issue for this?

  • I have searched the existing issues

Python version (python --version)

Python 3.14.7s

Scrapling version (scrapling.version)

0.4.15

Dependencies version (pip3 freeze)

anyio==4.14.1
apify_fingerprint_datapoints==0.15.0
asttokens==3.0.1
beautifulsoup4==4.15.0
browserforge==1.2.4
certifi==2026.6.17
cffi==2.1.0
click==8.4.2
cssselect==1.5.0
curl_cffi==0.16.1
decorator==5.3.1
executing==2.2.1
greenlet==3.5.3
idna==3.18
ipython==9.15.0
ipython_pygments_lexers==1.1.1
jedi==0.20.0
lxml==6.1.1
markdown-it-py==4.2.0
markdownify==1.2.3
matplotlib-inline==0.2.2
mdurl==0.1.2
msgspec==0.21.1
orjson==3.11.9
parso==0.8.7
patchright==1.62.1
pexpect==4.9.0
pip==26.2.1
playwright==1.62.0
prompt_toolkit==3.0.52
Protego==0.6.2
psutil==7.2.2
ptyprocess==0.7.0
pure_eval==0.2.3
pycparser==3.0
pyee==13.0.1
Pygments==2.20.0
rich==15.0.0
scrapling==0.4.15
six==1.17.0
soupsieve==2.8.4
stack-data==0.6.3
tld==0.13.2
traitlets==5.15.1
typing_extensions==4.16.0
w3lib==2.4.1
wcwidth==0.8.2

What's your operating system?

mac 26.6.2

Are you using a separate virtual environment?

Yes

Expected behavior

cannot use a period (.) in an ID selector.

% scrapling extract stealthy-fetch 'https://scrapling.readthedocs.io/en/latest/api-reference/response.html#scrapling.engines.toolbelt.custom.Response.markdown' test.md -s 'div:has(>#scrapling\\.engines\\.toolbelt\\.custom\\.Response\\.markdown)'
[2026-09-01 19:41:37] INFO: Fetched (200) <GET https://scrapling.readthedocs.io/en/latest/api-reference/response.html#scrapling.engines.toolbelt.custom.Response.markdown> (referer: https://www.google.com/)
Traceback (most recent call last):
  File "/Users/myuser/PycharmProjects/scrapling/venv/lib/python3.14/site-packages/scrapling/parser.py", line 610, in css
    xpath_selector = _css_to_xpath(selector)
  File "/Users/myuser/PycharmProjects/scrapling/venv/lib/python3.14/site-packages/scrapling/core/translator.py", line 134, in css_to_xpath
    return translator.css_to_xpath(query)
           ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
  File "/Users/myuser/PycharmProjects/scrapling/venv/lib/python3.14/site-packages/scrapling/core/translator.py", line 124, in css_to_xpath
    return super().css_to_xpath(css, prefix)
           ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "/Users/myuser/PycharmProjects/scrapling/venv/lib/python3.14/site-packages/cssselect/xpath.py", line 221, in css_to_xpath
    for selector in parse(css)
                    ~~~~~^^^^^
  File "/Users/myuser/PycharmProjects/scrapling/venv/lib/python3.14/site-packages/cssselect/parser.py", line 545, in parse
    return list(parse_selector_group(stream))
  File "/Users/myuser/PycharmProjects/scrapling/venv/lib/python3.14/site-packages/cssselect/parser.py", line 560, in parse_selector_group
    yield Selector(*parse_selector(stream))
                    ~~~~~~~~~~~~~~^^^^^^^^
  File "/Users/myuser/PycharmProjects/scrapling/venv/lib/python3.14/site-packages/cssselect/parser.py", line 569, in parse_selector
    result, pseudo_element = parse_simple_selector(stream)
                             ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "/Users/myuser/PycharmProjects/scrapling/venv/lib/python3.14/site-packages/cssselect/parser.py", line 703, in parse_simple_selector
    combinator, arguments = parse_relative_selector(stream)
                            ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "/Users/myuser/PycharmProjects/scrapling/venv/lib/python3.14/site-packages/cssselect/parser.py", line 763, in parse_relative_selector
    raise SelectorSyntaxError(f"Expected an argument, got {next_}")
cssselect.parser.SelectorSyntaxError: Expected an argument, got <HASH 'scrapling\' at 9>
% scrapling extract stealthy-fetch 'https://scrapling.readthedocs.io/en/latest/api-reference/response.html#scrapling.engines.toolbelt.custom.Response.markdown' test.md -s 'div:has(>#scrapling\.engines\.toolbelt\.custom\.Response\.markdown)' 
...
cssselect.parser.SelectorSyntaxError: Invalid CSS selector 'div:has(>#scrapling\.engines\.toolbelt\.custom\.Response\.markdown)': Expected an argument, got <HASH 'scrapling.engines.toolbelt.custom.Response.markdown' at 9>
scrapling extract stealthy-fetch 'https://scrapling.readthedocs.io/en/latest/api-reference/response.html#scrapling.engines.toolbelt.custom.Response.markdown' test.md -s 'div:has(>#scrapling\\\.engines\\\.toolbelt\\\.custom\\\.Response\\\.markdown)'
...
cssselect.parser.SelectorSyntaxError: Expected an argument, got <HASH 'scrapling\.engines\.toolbelt\.custom\.Response\.markdown' at 9>
scrapling extract stealthy-fetch 'https://scrapling.readthedocs.io/en/latest/api-reference/response.html#scrapling.engines.toolbelt.custom.Response.markdown' test.md -s 'div:has(>#scrapling\\\\.engines\\\\.toolbelt\\\
\.custom\\\\.Response\\\\.markdown)'
...
cssselect.parser.SelectorSyntaxError: Expected an argument, got <HASH 'scrapling\\' at 9>

Actual behavior

This syntax works in a browser.

> document.querySelectorAll('div:has(>#scrapling\\.engines\\.toolbelt\\.custom\\.Response\\.markdown)')
< NodeList [div.doc.doc-object.doc-function]0: div.doc.doc-object.doc-functionlength: 1[[Prototype]]: NodeList

Steps To Reproduce

You can test this from the command line, and you'll get the same result with Python code.

scrapling extract stealthy-fetch 'https://scrapling.readthedocs.io/en/latest/api-reference/response.html#scrapling.engines.toolbelt.custom.Response.markdown' test.md -s 'div:has(>#scrapling\\.engines\\.toolbelt\\.custom\\.Response\\.markdown)'

thank you.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdependency bugA bug occurred due to issues with one or more dependency updates.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions