【问题标题】:How to get a value out of bs4.element.Tag如何从 bs4.element.Tag 中获取值
【发布时间】:2021-06-04 18:59:12
【问题描述】:

我正在与BeautifulSoup 合作进行网络抓取项目。我有一个标签:

<span class="sal "><em class="iconRup"></em>40.0 Lacs</span>

我想从中检索40.0 Lacs

我尝试使用:

salary = soup.find('span', class_ = 'sal')
print(salary.string())

但这给出了一个 None object 。我该如何继续?

【问题讨论】:

    标签: python-3.x web-scraping beautifulsoup


    【解决方案1】:

    是这样的:

    from bs4 import BeautifulSoup
    
    html = """
    <span class="sal "><em class="iconRup"></em>40.0 Lacs</span>
    """
    
    soup = BeautifulSoup(html, "html.parser").find('span', class_='sal')
    print(soup.getText())
    

    输出:

    40.0 Lacs
    

    【讨论】:

      猜你喜欢
      • 2019-12-15
      • 1970-01-01
      • 2022-11-25
      • 1970-01-01
      • 2015-10-31
      • 2021-02-27
      • 1970-01-01
      • 2019-02-05
      • 1970-01-01
      相关资源
      最近更新 更多