【问题标题】:How to get the text of div class?如何获取 div 类的文本?
【发布时间】:2021-12-18 05:48:47
【问题描述】:

【问题讨论】:

  • find_all 返回一个没有文本属性的列表。
  • 那怎么解决呢?
  • 你可以使用find。如果您以文本而不是屏幕截图的形式分享 html,您的问题会更容易回答。
  • 我分享了上面的网站。

标签: python web web-scraping


【解决方案1】:

如果您想提取您在 cmets 中提到的 Zillow 数据的时间,您可以搜索具有适当类名的 div。

from bs4 import BeautifulSoup

html = """
<div class="hdp__sc-qe1dn6-1 jqZymu"><div class="Text-c11n-8-53-2__sc-aiai24-0 iBdXNb">Time on Zillow</div><div class="Text-c11n-8-53-2__sc-aiai24-0 duChdW">36 minutes</div></div>
"""

soup = BeautifulSoup(html, 'html.parser')
time = soup.find('div', class_="Text-c11n-8-53-2__sc-aiai24-0 duChdW")
print(time.text)
# 36 minutes

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多