“NoneType”对象没有属性“findAll”。怎么解决这个问题?

2024-09-27 23:15:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图下载一个表作为一个CSV文件,但我一直得到一个 AttributeError:“NoneType”对象没有属性“findAll”

from bs4 import BeautifulSoup as BS
import csv
import os

html1t = open("SOUP1.TABLE.ZKILL.HTML").read()
soup1t = BS(html1t)
table1 = soup1t.find('table')

output_rows = []
for table_row in table1.findAll('tr'):
    columns = table_row.find('td')
    output_row = []
    for column in columns:
        output_row.append(column.text)
    output_rows.append(output_row)

with open('./zkillboard1.csv', 'w') as csvfile:
    writer = csv.writer(csvfile)
    writer.writerows(output_rows)

Tags: csvimportoutputbsastableopenfind

热门问题