美丽的汤提取跨度标签之间的文本 [英] Beautiful soup extract text between span tags
本文介绍了美丽的汤提取跨度标签之间的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<span id="priceblock_dealprice" class="a-size-medium a-color-price"><span class="currencyINR"> </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"> </span> 33,990.00 </span>'
soup = BeautifulSoup(html, 'lxml')
text = soup.select_one('span.a-color-price').text.strip()
输出:
33,990.00
这篇关于美丽的汤提取跨度标签之间的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文