How to web scrap Economic Calendar data from TradingView and load into Dataframe?

I want to load the Economic Calendar data from TradingView link and load into Dataframe ?

Link: https://in.tradingview.com/economic-calendar/
Filter-1: Select Data for India and United States
Filter-2: Data for This Week

enter image description here

>Solution :

You can request this url: https://economic-calendar.tradingview.com/events

import pandas as pd
import requests

url = 'https://economic-calendar.tradingview.com/events'
today = pd.Timestamp.today().normalize()
payload = {
    'from': (today + pd.offsets.Hour(23)).isoformat() + '.000Z',
    'to': (today + pd.offsets.Day(7) + pd.offsets.Hour(22)).isoformat() + '.000Z',
    'countries': ','.join(['US', 'IN'])
}
data = requests.get(url, params=payload).json()
df = pd.DataFrame(data['result'])

Output:

>>> df
        id                                        title country  ...   ticker                                            comment scale
0   312843                         3-Month Bill Auction      US  ...      NaN                                                NaN   NaN
1   312844                         6-Month Bill Auction      US  ...      NaN                                                NaN   NaN
2   316430         LMI Logistics Managers Index Current      US  ...   USLMIC  The Logistics Managers Survey is a monthly stu...   NaN
3   316503                                      Exports      US  ...    USEXP  The United States is the world's third biggest...     B
4   316504                                      Imports      US  ...    USIMP  The United States is the world's second-bigges...     B
5   316505                             Balance of Trade      US  ...    USBOT  The United States has been running consistent ...     B
6   312845                                  Redbook YoY      US  ...     USRI  The Johnson Redbook Index is a sales-weighted ...   NaN
7   316509                   IBD/TIPP Economic Optimism      US  ...    USEOI  IBD/TIPP Economic Optimism Index measures Amer...   NaN
8   337599                      Fed Chair Powell Speech      US  ...   USINTR  In the United States, the authority to set int...   NaN
9   334599                          3-Year Note Auction      US  ...      NaN                                                NaN   NaN
10  337600                              Fed Barr Speech      US  ...   USINTR  In the United States, the authority to set int...   NaN
11  316449                       Consumer Credit Change      US  ...    USCCR  In the United States, Consumer Credit refers t...     B
12  312846                   API Crude Oil Stock Change      US  ...    USCSC  Stocks of crude oil refer to the weekly change...     M
13  316575                           Cash Reserve Ratio      IN  ...    INCRR  Cash Reserve Ratio is a specified minimum frac...   NaN
14  334653                   RBI Interest Rate Decision      IN  ...   ININTR  In India, interest rate decisions are taken by...   NaN
15  312847                    MBA 30-Year Mortgage Rate      US  ...     USMR  MBA 30-Year Mortgage Rate is average 30-year f...   NaN
16  312848                    MBA Mortgage Applications      US  ...   USMAPL  In the US, the MBA Weekly Mortgage Application...   NaN
17  312849                 MBA Mortgage Refinance Index      US  ...    USMRI  The MBA Weekly Mortgage Application Survey is ...   NaN
18  312850                    MBA Mortgage Market Index      US  ...    USMMI  The MBA Weekly Mortgage Application Survey is ...   NaN
19  312851                           MBA Purchase Index      US  ...   USPIND                                                NaN   NaN
20  337604                          Fed Williams Speech      US  ...   USINTR  In the United States, the authority to set int...   NaN
21  316553                    Wholesale Inventories MoM      US  ...     USWI  The Wholesale Inventories are the stock of uns...   NaN
22  337601                              Fed Barr Speech      US  ...   USINTR  In the United States, the authority to set int...   NaN
23  312852               EIA Refinery Crude Runs Change      US  ...    USRCR  Crude Runs refer to the volume of crude oil co...     M
24  312853                  EIA Crude Oil Stocks Change      US  ...   USCOSC  Stocks of crude oil refer to the weekly change...     M
25  312854                 EIA Distillate Stocks Change      US  ...    USDFS                                                NaN     M
26  312855                EIA Heating Oil Stocks Change      US  ...    USHOS                                                NaN     M
27  312856               EIA Gasoline Production Change      US  ...   USGPRO                                                NaN     M
28  312857                 EIA Crude Oil Imports Change      US  ...    USCOI                                                NaN     M
29  312858                   EIA Gasoline Stocks Change      US  ...   USGSCH  Stocks of gasoline refers to the weekly change...     M
30  312859          EIA Cushing Crude Oil Stocks Change      US  ...   USCCOS  Change in the number of barrels of crude oil h...     M
31  312860        EIA Distillate Fuel Production Change      US  ...    USDFP                                                NaN     M
32  337598                         17-Week Bill Auction      US  ...      NaN                                                NaN   NaN
33  334575                                 WASDE Report      US  ...      NaN                                                NaN   NaN
34  334586                         10-Year Note Auction      US  ...      NaN  Generally, a government bond is issued by a na...   NaN
35  337602                            Fed Waller Speech      US  ...   USINTR  In the United States, the authority to set int...   NaN
36  312933                          M3 Money Supply YoY      IN  ...     INM3  India Money Supply M3 includes M2 plus long-te...   NaN
37  312863                Jobless Claims 4-week Average      US  ...   USJC4W                                                NaN     K
38  312864                    Continuing Jobless Claims      US  ...    USCJC  Continuing Jobless Claims refer to actual numb...     K
39  312865                       Initial Jobless Claims      US  ...    USIJC  Initial jobless claims have a big impact in fi...     K
40  312866                EIA Natural Gas Stocks Change      US  ...   USNGSC  Natural Gas Stocks Change refers to the weekly...     B
41  312867                          8-Week Bill Auction      US  ...      NaN                                                NaN   NaN
42  312868                          4-Week Bill Auction      US  ...      NaN                                                NaN   NaN
43  334602                         30-Year Bond Auction      US  ...      NaN                                                NaN   NaN
44  312827                           Deposit Growth YoY      IN  ...     INDG  In India, deposit growth refers to the year-ov...   NaN
45  312869                    Foreign Exchange Reserves      IN  ...    INFER  In India, Foreign Exchange Reserves are the fo...     B
46  337022                         Bank Loan Growth YoY      IN  ...     INLG  In India, bank loan growth refers to the year-...   NaN
47  316685                    Industrial Production YoY      IN  ...   INIPYY  In India, industrial production measures the o...   NaN
48  316687                 Manufacturing Production YoY      IN  ...  INMPRYY  Manufacturing production measures the output o...   NaN
49  312902          Michigan Consumer Expectations Prel      US  ...    USMCE  The Index of Consumer Expectations focuses on ...   NaN
50  312903             Michigan Current Conditions Prel      US  ...   USMCEC  The Index of Consumer Expectations focuses on ...   NaN
51  312904  Michigan 5 Year Inflation Expectations Prel      US  ...  USMIE5Y  The Index of Consumer Expectations focuses on ...   NaN
52  312905         Michigan Inflation Expectations Prel      US  ...  USMIE1Y  The Index of Consumer Expectations focuses on ...   NaN
53  312906             Michigan Consumer Sentiment Prel      US  ...    USCCI  The Index of Consumer Expectations focuses on ...   NaN
54  337603                            Fed Waller Speech      US  ...   USINTR  In the United States, the authority to set int...   NaN
55  312870                   Baker Hughes Oil Rig Count      US  ...    USCOR  US Crude Oil Rigs refer to the number of activ...   NaN
56  335652                 Baker Hughes Total Rig Count      US  ...      NaN  US Total Rigs refer to the number of active US...   NaN
57  335824                     Monthly Budget Statement      US  ...    USGBV  Federal Government budget balance is the diffe...     B
58  337605                            Fed Harker Speech      US  ...   USINTR  In the United States, the authority to set int...   NaN

[59 rows x 16 columns]

Info:

>>> df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 59 entries, 0 to 58
Data columns (total 16 columns):
 #   Column      Non-Null Count  Dtype  
---  ------      --------------  -----  
 0   id          59 non-null     object 
 1   title       59 non-null     object 
 2   country     59 non-null     object 
 3   indicator   59 non-null     object 
 4   period      59 non-null     object 
 5   source      59 non-null     object 
 6   actual      0 non-null      object 
 7   previous    51 non-null     float64
 8   forecast    9 non-null      float64
 9   currency    59 non-null     object 
 10  unit        28 non-null     object 
 11  importance  59 non-null     int64  
 12  date        59 non-null     object 
 13  ticker      49 non-null     object 
 14  comment     44 non-null     object 
 15  scale       20 non-null     object 
dtypes: float64(2), int64(1), object(13)
memory usage: 7.5+ KB

Leave a Reply