, если вы хотите исправить это, см. bs4/element.py
строку 1440, замените
tokens = shlex.split(selector)
на
selector = re.sub(r'\s*([+>~])\s*', r' \1 ', selector)
tokens = shlex.split(selector)
Демо:
<script type="text/javascript" src="//cdn.datacamp.com/dcl-react.js.gz"></script>
<div data-datacamp-exercise data-lang="python">
<code data-type="sample-code">
import re, shlex
def testSelect(selector):
selector = re.sub(r'\s*([+>~])\s*', r' \1 ', selector)
tokens = shlex.split(selector)
print(tokens)
testSelect('#mainbar > div ~ p') # default
testSelect('#mainbar>div~p')
testSelect('#mainbar >div+ p')
testSelect('#mainbar.classA')
testSelect('#mainbar p')
</code>
</div>