investpy icon indicating copy to clipboard operation
investpy copied to clipboard

Getting historical data of economic calendar

Open woreom opened this issue 1 year ago • 1 comments

Hi, first of all, thank you for the great package.

I'm trying to get the historical data of economic news such as GDP and ADP and etc, your package doesn't have such a function? I read your code, and it seems you're creating a head and data for your request, can you help me do the same thing for my task as well?

I have gathered the URL name of most of this news for example, "https://www.investing.com/economic-calendar/"+"10-year-note-auction-571" is U.S. 10-Year Note Auction or cpi-1063 is New Zealand Consumer Price Index (CPI) YoY.

and wrote this for your code:

headers = {
    "User-Agent": random_user_agent,
    "X-Requested-With": "XMLHttpRequest",
    "Accept": "text/html",
    "Accept-Encoding": "gzip, deflate",
    "Connection": "keep-alive",
}

data = {
        "dateFrom": "2008-01-01",
        "dateTo": "2022-07-25",
        "timeZone": choice([19]),
        "timeFilter": "timeOnly",
        "currentTab": "custom",
        "submitFilters": 1,
        "limit_from": 0,
        }

url = "https://www.investing.com/economic-calendar/10-year-note-auction-571"

req = requests.post(url, headers=headers, data=data)

but req.json() raises an error, instead I used .content and I'm getting the table but I can't change the dateFrom and dateTo so only 5 rows are shown.

Release Date	Time	Actual	Forecast	Previous	Unnamed: 5
0	Jul 12, 2022	21:30	2.960%	NaN	3.030%	NaN
1	Jun 08, 2022	21:30	3.030%	NaN	2.943%	NaN
2	May 11, 2022	21:31	2.943%	NaN	2.720%	NaN
3	Apr 12, 2022	21:30	2.720%	NaN	1.920%	NaN
4	Mar 09, 2022	22:31	1.920%	NaN	1.904%	NaN
5	Feb 09, 2022	22:30	1.904%	NaN	1.723%	NaN

woreom avatar Jul 25 '22 15:07 woreom

I did this (economic calendar) totally on my own but can tell you they introduced mid of May some kind of cloudflare protection, still have to find out how to circumvent..

bufemc avatar May 28 '23 12:05 bufemc