Issue
Here I have a simple code that is not seeming to do what I am trying to do. The goal of this code is to retrieve the value of the stock that the user inputs.
ticker = input("What stock would you like to track?: (enter the ticker) ")
r = requests.get(f"https://www.marketwatch.com/investing/stock/{ticker}?mod=search_symbol").text
webpage = BeautifulSoup(r, 'html.parser')
locate = webpage.find('bq-quote', {'class': 'value'})
print(locate)
Although the value of the stock is inside the class value it does not seem to be returning anything. web.find_all() just returns '[]' so I am not sure what I am doing wrong here.
Solution
This works.
from bs4 import BeautifulSoup
import requests
ticker = input("What stock would you like to track?: (enter the ticker) ")
r = requests.get(f"https://www.marketwatch.com/investing/stock/{ticker}?mod=search_symbol",).text
webpage = BeautifulSoup(r, "html.parser")
locate = webpage.find(class_="value")
stock_price = locate.text
print(stock_price)
Answered By - juanpethes
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.