从带有漂亮汤的标签中获取文本,除了

问题描述 投票:0回答:1
python web-scraping beautifulsoup
1个回答
0
投票

您可以使用带有伪类的

css selector
来始终获得第一个
<small>
:

soup.select('tr > td:first-of-type > small:first-of-type')

要根据您的示例获取所有标题,请使用

list comprhension
:

[title.get_text(strip=True).split('   ')[-1] for title in soup.select('tr > td:first-of-type > small:first-of-type')]

结果:

['EFURIX CREM 15 GR S VALEA', 'ASDRON XPE FR 100ML', 'DIAD  0,75MGC/ 2 COMP']
© www.soinside.com 2019 - 2024. All rights reserved.