我是 Yahoo Finance API 的用户。我最近收到错误消息,说程序无法读取网站。这是错误信息:
请注意,我为此使用了 Pandas Datareader。
Traceback (most recent call last):
File "C:/Users/sande/Dropbox/My PC (DESKTOP-BOCOF1O)/Desktop/Vihaan/ThirdPartySoftware/Python/DadWork/Downloaders/YahooDownloader.py", line 38, in <module>
df = pdr.get_data_yahoo(str(file_name), start, end)
File "C:\Users\sande\Dropbox\My PC (DESKTOP-BOCOF1O)\Desktop\Vihaan\ThirdPartySoftware\Python\DadWork\Downloaders\venv\lib\site-packages\pandas_datareader\data.py", line 86, in get_data_yahoo
return YahooDailyReader(*args, **kwargs).read()
File "C:\Users\sande\Dropbox\My PC (DESKTOP-BOCOF1O)\Desktop\Vihaan\ThirdPartySoftware\Python\DadWork\Downloaders\venv\lib\site-packages\pandas_datareader\base.py", line 253, in read
df = self._read_one_data(self.url, params=self._get_params(self.symbols))
File "C:\Users\sande\Dropbox\My PC (DESKTOP-BOCOF1O)\Desktop\Vihaan\ThirdPartySoftware\Python\DadWork\Downloaders\venv\lib\site-packages\pandas_datareader\yahoo\daily.py", line 153, in _read_one_data
resp = self._get_response(url, params=params)
File "C:\Users\sande\Dropbox\My PC (DESKTOP-BOCOF1O)\Desktop\Vihaan\ThirdPartySoftware\Python\DadWork\Downloaders\venv\lib\site-packages\pandas_datareader\base.py", line 181, in _get_response
raise RemoteDataError(msg)
pandas_datareader._utils.RemoteDataError: Unable to read URL: https://finance.yahoo.com/quote/GILD/history?period1=1152743400&period2=1626215399&interval=1d&frequency=1d&filter=history
Response Text:
b'<!DOCTYPE html>\n <html lang="en-us"><head>\n <meta http-equiv="content-type" content="text/html; charset=UTF-8">\n <meta charset="utf-8">\n <title>Yahoo</title>\n <meta name="viewport" content="width=device-width,initial-scale=1,minimal-ui">\n <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">\n <style>\n html {\n height: 100%;\n }\n body {\n background: #fafafc url(https://s.yimg.com/nn/img/sad-panda-201402200631.png) 50% 50%;\n background-size: cover;\n height: 100%;\n text-align: center;\n font: 300 18px "helvetica neue", helvetica, verdana, tahoma, arial, sans-serif;\n }\n table {\n height: 100%;\n width: 100%;\n table-layout: fixed;\n border-collapse: collapse;\n border-spacing: 0;\n border: none;\n }\n h1 {\n font-size: 42px;\n font-weight: 400;\n color: #400090;\n }\n p {\n color: #1A1A1A;\n }\n #message-1 {\n font-weight: bold;\n margin: 0;\n }\n #message-2 {\n display: inline-block;\n *display: inline;\n zoom: 1;\n max-width: 17em;\n _width: 17em;\n }\n </style>\n <script>\n document.write(\'<img src="//geo.yahoo.com/b?s=1197757129&t=\'+new Date().getTime()+\'&src=aws&err_url=\'+encodeURIComponent(document.URL)+\'&err=%<pssc>&test=\'+encodeURIComponent(\'%<{Bucket}cqh[:200]>\')+\'" width="0px" height="0px"/>\');var beacon = new Image();beacon.src="//bcn.fp.yahoo.com/p?s=1197757129&t="+new Date().getTime()+"&src=aws&err_url="+encodeURIComponent(document.URL)+"&err=%<pssc>&test="+encodeURIComponent(\'%<{Bucket}cqh[:200]>\');\n </script>\n </head>\n <body>\n <!-- status code : 404 -->\n <!-- Not Found on Server -->\n <table>\n <tbody><tr>\n <td>\n <img src="https://s.yimg.com/rz/p/yahoo_frontpage_en-US_s_f_p_205x58_frontpage.png" alt="Yahoo Logo">\n <h1 style="margin-top:20px;">Will be right back...</h1>\n <p id="message-1">Thank you for your patience.</p>\n <p id="message-2">Our engineers are working quickly to resolve the issue.</p>\n </td>\n </tr>\n </tbody></table>\n </body></html>'
这是主要代码:
import pandas as pd
import pandas_datareader as pdr
import os
import datetime
import openpyxl
# Paths for loading file to read
path_file = os.getcwd() + "\\Book1.xlsx"
path = os.getcwd() + "\\historicalData"
# Load File
wb_obj = openpyxl.load_workbook(path_file)
sheet_obj = wb_obj.active
max_row = sheet_obj.max_row
# Get 15 years ago date
dt = datetime.datetime.now()
dt = dt.replace(year=dt.year-15)
dty = dt.year
dtm = dt.month
dtd = dt.day
for q in range(1):
#try:
for i in range(1, max_row + 1):
#try:
cell_obj = sheet_obj.cell(row = i, column = 1)
file_name = str(cell_obj.value).upper()
print(file_name)
# Download Path for data
download_source = (r"" + path + "\\" + str(file_name) + ".csv")
start = datetime.datetime(dty, dtm, dtd)
end = datetime.datetime.today()
df = pdr.get_data_yahoo(str(file_name), start, end)
df.to_csv(download_source)
print(df)
"""
except Exception as e:
print(str(file_name) + " Not Found!")
except Exception as e:
print(e)
break
"""
(请忽略引号)
请问有人可以帮忙吗?
答案 0 :(得分:2)
你甚至查看过你取回的数据吗?
<h1 style="margin-top:20px;">Will be right back...</h1>
<p id="message-1">Thank you for your patience.</p>
<p id="message-2">Our engineers are working quickly to resolve the issue.</p>