Last active
July 12, 2021 08:40
-
-
Save fredchu/67490bf3513674145f0758045c49fef4 to your computer and use it in GitHub Desktop.
Use pandas_datareader with user agent and session
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# reference: | |
# _get_response without headers doesn't work (at least with 'yahoo' source #867 https://github.com/pydata/pandas-datareader/issues/867 | |
from pandas_datareader import DataReader | |
import requests | |
USER_AGENT = { | |
'User-Agent': ('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)' | |
' Chrome/91.0.4472.124 Safari/537.36') | |
} | |
sesh = requests.Session() | |
sesh.headers.update(USER_AGENT) | |
tw2330 = DataReader('2330.TW', data_source='yahoo', start='2000-01-01', session=sesh) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment