|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import matplotlib.pylab as plt
import requests
from bs4 import BeautifulSoup as bs
from pylab import*
rcParams['font.sans-serif'] = ['SimHei']
year = []
gdp = []
url = 'http://value500.com/M2GDP.html'
content =requests.get(url)
content1 = content.text
parse = bs(content1, 'html.parser')
data1 = parse.find_all('table')
rows = data1[19].find_all('tr')
i = 0
for row in rows:
cols = row.find_all('tr')
if(len(cols) > 0 and i == 0):
i += 1
else:
year.append(cols[0].text[0:3])
gdp.append(cols[2].text)
plt.plot(year, gdp, lw = 2.0)
plt.title('1990-2017年度我国GDP')
plt.xlabel('年份')
plt.ylabel('GDP(亿元)')
plt.show()
这是我在一本书上看到的例题,输出时总是说“列表索引超出范围”。求解不知道问题出在哪里?
|
|