问题遇到的现象和发生背景
网路爬虫
问题相关代码,请勿粘贴截图
import requests
from bs4 import BeautifulSoup
url='https://www.endata.com.cn/BoxOffice/BO/Year/index.html'
headers={'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.134 Safari/537.36 Edg/103.0.1264.71'}
response=requests.get(url=url,headers=headers)
text=response.text
main_page= BeautifulSoup(text,'html.parser')
table=main_page.find('table class="bo-table img-table"')
f=open('电影票房.csv',mode='a')
trs=table.find_all('tr class')
for tr in trs:
lst=tr.find_all('td')
if len(lst)!=0:
for td in lst:
f.write(td.text)
f.write(',')
f.write('\n')
运行结果及报错内容
Traceback (most recent call last):
File "C:\Users\盈下一片天\Desktop\爬票房.py", line 11, in
trs=table.find_all('tr class')
AttributeError: 'NoneType' object has no attribute 'find_all'
我的解答思路和尝试过的方法
为什么会出现这个错误啊