I'm a bit confused by using CSS selectors with axis combinators in BeautifulSoup. Below is the simple code to illustrate what I mean:
from bs4 import BeautifulSoup as bs
import requests
response = requests.get('https://stackoverflow.com/questions/tagged/python')
soup = bs(response.text)
print(len(soup.select('#mainbar > div')))
returns 6
children... but
print(len(soup.select('#mainbar>div')))
returns 0
children...
The same with '#mainbar ~ div'
(found 1 sibling) and #mainbar~div'
(found nothing)
From documentation those spaces are optional, but in fact I got different output with BeautifulSoup for the same selectors (as I thought)
So is it bs4
bug or this behavior depends on version of CSS or something else?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…