Open FanaticPythoner opened 1 year ago
Please use spaces between >
as recommended in CSS specification.
@FanaticPythoner
Please see white-space in selectors. But, in the last lexbor version "combinators" normal work without whitespaces.
I understand that. It is still, however, my strong belief that these cases should still be handled by the library, as it is far from everyone that follows best practices. Moreover, people, such as me, obtaining those selectors via parsing the CSS files in a given web page don't have control over whether or not the person who made the CSS declarations in said CSS files followed good practices.
@rushter @lexborisov
In the meantime, for those reading this thread, you can simply do something like that in your code prior to calling HTMLParser.css():
chars_to_patch = [
'>',
'+',
'~'
]
for c in chars_to_patch:
c_spaces = ' ' + c + ' '
if c in selector_str and c_spaces not in selector_str:
selector_str = selector_str.replace(c, c_spaces).replace(' ', ' ')
I understand that. It is still, however, my strong belief that these cases should still be handled by the library, as it is far from everyone that follows best practices. Moreover, people, such as me, obtaining those selectors via parsing the CSS files in a given web page don't have control over whether or not the person who made the CSS declarations in said CSS files followed good practices.
I can't fix it on my side. Adding whitespaces by using similar approach to yours is risky, so we need this to be fixed in the Modest engine. Is there anything that stops you from using the lexbor backend instead? It's an improved version of the parser, but it's not 100% compatible with the modest.
Here is a list of CSS selectors which should work, but instead throw "Bad CSS Selectors". I'm using selectolax.parser.HTMLParser with no other parameter than the HTML to parse, as well as the HTMLParser.css() function.