小编Cha*_*gen的帖子

未获取数据 Web.DataReader Panda

当我尝试从整个标准普尔 500 指数创建 CSV 文件时收到此错误消息:

Exception has occurred: pandas_datareader._utils.RemoteDataError
Run Code Online (Sandbox Code Playgroud)

没有使用 YahooDailyReader 获取符号 3M 公司的数据

我认为这是有问题的:

for row in table.findAll('tr') [1:]:
    ticker = row.findAll('td')[0:].text
Run Code Online (Sandbox Code Playgroud)

有人能帮帮我吗?提前致谢。

完整代码-

import bs4 as bs
import datetime as dt
import os
import pandas_datareader.data as web
import pickle
import requests

def save_sp500_tickers():
    resp = requests.get('http://en.wikipedia.org/wiki/List_of_S%26P_500_companies')
    soup = bs.BeautifulSoup(resp.text, 'lxml')
    table = soup.find('table', {'class': 'wikitable sortable'})
    tickers = []

    for row in table.findAll('tr') [1:]:
        ticker = row.findAll('td')[0:].text
        tickers.append(ticker)
    with open("sp500tickers.pickle", "wb") as f:
        pickle.dump(tickers, f)
    return tickers

# …
Run Code Online (Sandbox Code Playgroud)

python finance

3
推荐指数
2
解决办法
8995
查看次数

标签 统计

finance ×1

python ×1