【问题标题】:How to extract the variable name by using BeautifulSoup如何使用 BeautifulSoup 提取变量名
【发布时间】:2022-11-28 01:10:34
【问题描述】:

<td class="right" data-stat="players_used">23</td> 试图通过 BeautifulSoup 提取字符串“players_used”。

目前,我能够从此标签中提取内容,但我不知道如何通过 BeautifulSoup 提取字符串“players_used”。有人可以看看这个吗?

【问题讨论】:

    标签: web-scraping beautifulsoup


    【解决方案1】:

    只需使用.get() 来提取属性值:

    from bs4 import BeautifulSoup
    
    soup = BeautifulSoup('<td class="right" data-stat="players_used">23</td>')
    
    soup.find('td').get('data-stat')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-05
      • 1970-01-01
      • 2020-08-11
      • 2020-12-23
      • 1970-01-01
      • 2020-07-23
      • 2018-03-25
      • 1970-01-01
      相关资源
      最近更新 更多