求解决AttributeError: ‘NoneType‘ object has no attribute ‘find_all‘问题

运行爬虫程序的时候报错了,报错情况如下:

 有没有大神可以告诉我这是什么引起的,具体应该怎么解决

爬虫主要实现的是爬取国内GDP生产总值,并实现数据可视化,把源代码放在下面

源代码:

from bs4 import BeautifulSoup
import csv
import requests

headers = {
'User-Agent':
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36'
}

with open('中国国内生产总值.csv', 'w', newline='') as csv_out_file:
    head_list = ['季度', '国内生产总值-绝对值(亿元)', '国内生产总值-同比增长', '第一产业-绝对值(亿元)', '第一产业-同比增长',
            '第二产业-绝对值(亿元)', '第二产业-同比增长', '第三产业-绝对值(亿元)', '第三产业-同比增长']
    filewriter = csv.writer(csv_out_file)
    filewriter.writerow(head_list)

    for page in range(1, 4):
        url = 'https://data.eastmoney.com/cjsj/gdp.html' + str(page)
        response = requests.get(url=url, headers=headers)
        page_text = response.text

        soup = BeautifulSoup(page_text, 'html.parser')
        table = soup.find('table', attrs={'class':'table-model'})
        tr_list = table.find_all('tr')
        tr_list.pop(-1)
        for i in range(2):
            tr_list.pop(0)

        for tr in tr_list:
            info = tr.text.replace(' ', '').replace('\r', '').replace('\n', ' ').lstrip().rstrip()
            info_list = info.split()
            filewriter.writerow(info_list)


from pyecharts import Line

Quarter = []
GDP = []
Primary_industry = []
Secondary_industry = []
Tertiary_industry = []

with open('中国国内生产总值.csv', 'r', newline='') as csv_in_file:
    filereader = csv.reader(csv_in_file)
    head = next(filereader)
    for row_list in filereader:
        Quarter.append(row_list[0])
        gdp = round(eval(row_list[2][:-1]) / 100, 3)
        GDP.append(gdp)
        pri = round(eval(row_list[4][:-1]) / 100, 3)
        Primary_industry.append(pri)
        sec = round(eval(row_list[6][:-1]) / 100, 3)
        Secondary_industry.append(sec)
        ter = round(eval(row_list[8][:-1]) / 100, 3)
        Tertiary_industry.append(ter)

Quarter = Quarter[::-1]
GDP = GDP[::-1]
Primary_industry = Primary_industry[::-1]
Secondary_industry = Secondary_industry[::-1]
Tertiary_industry = Tertiary_industry[::-1]

Quarter = Quarter[::-1]
GDP = GDP[::-1]
Primary_industry = Primary_industry[::-1]
Secondary_industry = Secondary_industry[::-1]
Tertiary_industry = Tertiary_industry[::-1]

line = Line('中国国内生产总值同比增长率', '时间:2006年第1季度-2021年第3季度  数据来源:东方财富网', width=1280, height=720)
line.add('国内生产总值', Quarter, GDP, is_smooth=False, mark_point=['max'], mark_line=['average'], legend_pos='right')
line.add('第一产业', Quarter, Primary_industry, is_smooth=False, mark_point=['max'], mark_line=['average'],
         legend_pos='right')
line.add('第二产业', Quarter, Secondary_industry, is_smooth=False, mark_point=['max'], mark_line=['average'],
         legend_pos='right')
line.add('第三产业', Quarter, Tertiary_industry, is_smooth=False, mark_point=['max'], mark_line=['average'],
         legend_pos='right')
line.render('中国国内生产总值.html')
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值