Navigation

    SmartAPI Forum
    • Register
    • Login
    • Search
    • Categories
    • Popular
    • Groups
    • FAQs
    • API Docs

    Holiday List using BeautifulSoup using angelone.in

    Python SDK
    0
    1
    21
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Mnagesh
      Mnagesh last edited by

      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

      Now I am full time Algo Trader and successfully developed my own Apps for my personal use.

      1 Reply Last reply Reply Quote 0
      • First post
        Last post