美丽的汤提取跨度标签之间的文本

问题描述:

<span id="priceblock_dealprice" class="a-size-medium a-color-price"><span class="currencyINR">&nbsp;&nbsp;</span> 33,990.00 </span>

我需要从上面的html中提取数字33,990.00.

I need to extract the numbers 33,990.00 from the above html.

为什么使用?没必要如果页面是JavaScript呈现的,则仅使用 selenium .否则,请使用以下内容:

Why use selenium? It's so unnecessary. Only use selenium if the page is JavaScript rendered. Otherwise use the following:

from bs4 import BeautifulSoup
html = '<span id="priceblock_dealprice" class="a-size-medium a-color-price"><span class="currencyINR">&nbsp;&nbsp;</span> 33,990.00 </span>'
soup = BeautifulSoup(html, 'lxml')
text = soup.select_one('span.a-color-price').text.strip()

输出:

33,990.00