My goal is to scrape the stock price of the company which user will enter in the input box, but I am getting this error.
When I'm running the code without input block it's running fine, I don't know what's wrong with it.
from bs4 import BeautifulSoup
import requests
inp=input('company name')+":nse"
url1="https://www.google.com/finance/quote/"+inp.upper()
print(url1)
main_links=requests.get(url).text
soups=BeautifulSoup(main_link,'lxml')
stock_price=soup.find('div',class_="YMlKec fxKbKc").text
print(stock_price.text)
Output:
company nametatamotors:nse
https://www.google.com/finance/quote/TATAMOTORS:NSE
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/var/folders/nz/ccxxqn4x7rn2k4784tjpdd2c0000gn/T/ipykernel_2968/3667408284.py in <module>
5 soups=BeautifulSoup(main_link,'lxml')
6 stock_price=soup.find('div',class_="YMlKec fxKbKc")
----> 7 print(stock_price.text)
AttributeError: 'NoneType' object has no attribute 'text'