【问题标题】:Scrape price from span tag using BS4使用 BS4 从 span 标签中刮取价格
【发布时间】:2020-04-23 18:55:55
【问题描述】:

我正在尝试讨价还价,但我无法退货。 span 标签中包含我认为可能导致问题的数据量。

看起来像这样

<span class="productPrice" data-amount style>€ 100.00</span>

我试过了:

price = soup.find("span", class_="productPrice").get_text()

但是没有运气。

任何帮助都将不胜感激!

【问题讨论】:

  • 建议:尝试.text 而不是.get_text()

标签: python beautifulsoup scrape


【解决方案1】:

代码应如下所示:

from bs4 import BeautifulSoup

soup = BeautifulSoup('your_html_to_parse', 'html.parser')
span = soup.find("span", class_="productPrice")
print(span.text)

结果就是你的情况:

€ 100.00

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-26
    • 1970-01-01
    • 2021-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多