我想从下面的中刮取2015:

我使用下面的代码,但只能刮掉"Annee“
soup.find('span', {'class':'optionLabel'}).get_text()有人能帮忙吗?
我是个新学习者。
发布于 2022-05-10 18:40:09
只需尝试找到它的下一个保存要刮的文本的span:
soup.find('span', {'class':'optionLabel'}).find_next('span').get_text()或css selectors与adjacent sibling combinator
soup.select_one('span.optionLabel + span').get_text()示例
html='''
<span class="optionLabel"><button>Année</button</span> :
<span>2015</span>'''
from bs4 import BeautifulSoup
soup = BeautifulSoup(html)
soup.find('span', {'class':'optionLabel'}).find_next('span').get_text()输出
2015https://stackoverflow.com/questions/72191374
复制相似问题