[Python] Getting stock prices from internet using web scraping

Discussão em 'Python' iniciado por Stack, Julho 24, 2025.

  1. Stack

    Stack Membro Participativo

    Output of my code:


    <Response [200]>
    https://www.tradingview.com/symbols/NSE-RELIANCE
    1
    [<div class="tv-symbol-price-quote__value js-symbol-last"></div>]

    Process Finished with exit code 0


    I am trying to read stock name from a excel file and update their latest price in my excel sheet using this code. After running this code I am getting the output in a array(data) but that does not contain any stock price, which i could later retrieve and update in my list. Can someone please help me in this?The html tag highlighted containing the price of stock

    import openpyxl
    import time
    import requests
    from bs4 import BeautifulSoup
    wb = openpyxl.load_workbook("try.xlsx")
    sheets = wb.sheetnames
    #print(sheets)
    sh = wb['Stock']
    data = sh['F4'].value
    #print(data)
    s_row = 4
    s_col = 6
    c_list = []
    while sh.cell(row=s_row, column= s_col).value != None:
    c_name = sh.cell(row=s_row, column=s_col).value
    c_list.append(c_name)
    s_row += 1
    #print("Company name available in Database")
    #[print(' ->', name) for name in c_list]
    time.sleep(2)
    for stock_symbol in c_list:
    url = 'https://www.tradingview.com/symbols/NSE-' + stock_symbol
    response = requests.get(url)
    print(response)
    print(url)
    soup = BeautifulSoup(response.text, 'html.parser')
    #print(soup)
    data = soup.find_all('div', attrs={'class': 'tv-symbol-price-quote__value js-symbol-last'})
    print(len(data))
    print(data)

    Continue reading...

Compartilhe esta Página