Python 美丽汤-如何获得美丽汤中的第二道菜? 索赔日期:2018年9月26日
在找到Python 美丽汤-如何获得美丽汤中的第二道菜? 索赔日期:2018年9月26日,python,html,web-scraping,beautifulsoup,Python,Html,Web Scraping,Beautifulsoup,在找到索赔日期后,我想查找上面的2018年9月26日文本: 我尝试了findNext,find\u next\u sibling和许多其他建议 有多个\ngcontent2和文本主 谢谢您的帮助。您可以使用regex.Import-re。然后找到span标记的文本,然后找到下一个span标记 <div _ngcontent-c2=""><span _ngcontent-c2="" class="text-secondary">Claim date: </span&g
索赔日期后,我想查找上面的2018年9月26日文本:
我尝试了findNext
,find\u next\u sibling
和许多其他建议
有多个\ngcontent2
和文本主
谢谢您的帮助。您可以使用regex.Import-re。然后找到span标记的文本,然后找到下一个span标记
<div _ngcontent-c2=""><span _ngcontent-c2="" class="text-secondary">Claim date: </span><span _ngcontent-c2="" class="text-primary">26 September, 2018</span></div>
或者,如果您拥有bs4 4.7.1或更高版本,您可以使用css选择器
26 September, 2018
html=''索赔日期:2018年9月26日''
soup=BeautifulSoup(html,'html.parser')
打印(soup.select_one('span:contains(“索赔日期”))。查找_next('span')。文本)
26 September, 2018
html='''<div _ngcontent-c2=""><span _ngcontent-c2="" class="text-secondary">Claim date: </span><span _ngcontent-c2="" class="text-primary">26 September, 2018</span></div>'''
soup=BeautifulSoup(html,'html.parser')
print(soup.select_one('span:contains("Claim date:")').find_next('span').text)