admin管理员组文章数量:1435778
I have been attempting to web scrape data from yahoo finance specifically on historical data of S&P 500 which its webpage url is '/%5EGSPC/history/?period1=1574074965&period2=1731927744'
As you can see from the picture below, it seems that yahoo finance is not providing access to my act of web scraping. Is there any other solution to overcome this and web scrape the data
S&P 500 data
I have been attempting to web scrape data from yahoo finance specifically on historical data of S&P 500 which its webpage url is 'https://finance.yahoo/quote/%5EGSPC/history/?period1=1574074965&period2=1731927744'
As you can see from the picture below, it seems that yahoo finance is not providing access to my act of web scraping. Is there any other solution to overcome this and web scrape the data
S&P 500 data
Share Improve this question asked Nov 18, 2024 at 11:29 jumbojumbo 111 bronze badge 2- Can you confirm whether you want the Table of content available in the URL you provided? – Moses01 Commented Nov 18, 2024 at 11:59
- Please make sure to post code and console output as code-fenced text, not images. Images can't be copy-pasted, load slower, take more bandwidth, and are less accessible. – Anerdw Commented Nov 19, 2024 at 0:21
1 Answer
Reset to default 2Since the URL you use is Yahoo Finance and it is redirecting to multiple sites and fetching the data, but the beautifulsoup you use can try fetch up to 30 redirects only.
Instead of using Web Scrap, You can use Yahoo Finance module for Python. I noticed, You wanted to fetch the data from Nov 18,2019 to Nov 18,2024
So please use this code below to get the required data. You can change the dates as per your wish or use the below line to get all data
data = sp500.history(period="max")
Here is the code you should use:
import yfinance as yf
ticker = "^GSPC"
data = yf.Ticker(ticker)
hist = data.history(start="2019-11-18", end="2024-11-18") # Specify date range
hist.to_csv("sp500_data.csv")
本文标签:
版权声明:本文标题:python - Trying to web scrape S&P500 data from Yahoo Finance but cannot retrieve despite all right format - Stack Overfl 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745621615a2666716.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论