【问题标题】:Accessing data within the class description with beautiful soup用漂亮的汤访问类描述中的数据
【发布时间】:2017-04-06 21:12:44
【问题描述】:

我想抓取一个网站,但我感兴趣的数据在类描述中:

<td class="cars" horse-power="276"></td>

使用以下方法解析整个表:

for row in table.find_all('tr'): 
    column = row.find_all('td')

我尝试了各种不同的方法,但到目前为止没有任何效果。我如何访问这些数据?

【问题讨论】:

标签: python html beautifulsoup


【解决方案1】:
for row in table.find_all('tr'): 
    td_class = [td.get('class') for td in row.find_all('td')]
    td_horse-power = [td.get('horse-power') for td in row.find_all('td')]

【讨论】:

    【解决方案2】:
    for row in table.find_all('tr'): 
        for td in row.find_all('td'):
            print td.attrs['class']
    

    【讨论】:

      猜你喜欢
      • 2021-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-22
      • 1970-01-01
      • 1970-01-01
      • 2020-04-17
      • 1970-01-01
      相关资源
      最近更新 更多