Holiday List using BeautifulSoup using angelone.in


  • By web scraping we can get the holiday list into data-frame.

    import requests
    from bs4 import BeautifulSoup
    import pandas as pd
    
    
    # URL of the webpage containing the data table
    url = 'https://www.angelone.in/nse-holidays-2024'
    
    # Send a GET request to the webpage
    response = requests.get(url)
    
    if response.status_code == 200:
        # Parse the HTML content of the webpage
        soup = BeautifulSoup(response.content, 'html.parser')
        
        # Find the data table by inspecting the webpage's HTML structure
        # For example, if the data table is in a <table> element with class 'data-table'
        data_table = soup.find('table', class_='inner-table')
        r1 = []
        # Extract data from the table (example: print the table content)
        if data_table:
            rows = data_table.find_all('tr')
            
            for row in rows:
                #print(row)
                columns = row.find_all('td')
                #########
                if not columns:
                    columns = row.find_all('th')
                    colnames1 = [column.get_text() for column in columns]
                else:
                    row_data = [column.get_text() for column in columns]
                    r1.append(row_data)
                    #print(row_data)
            dfholiday = pd.DataFrame(r1,columns = colnames1 ) 
        else:
            print("No data table found on the webpage.")
    else:
        print("Failed to retrieve webpage. Status code:", response.status_code)
    
    
    print(dfholiday)
    
    

    output :
    180fe506-7677-410b-8b3b-663a5f927aa7-image.png