![]() Fundamental company data and analyst estimates provided by FactSet. International stock quotes are delayed as per exchange requirements. stock quotes reflect trades reported through Nasdaq only comprehensive quotes and volume reflect trading in all markets and are delayed at least 15 minutes. With this article at OpenGenus, you must have a strong idea of how to get the current stock price using Beautiful Soup and the Requests library.Stocks: Real-time U.S. ![]() Output Current AAPL stock price is 149.32 Soup = BeautifulSoup(response.text, "html.parser")įor symbol in "AAPL AMZN IBM GOOG MSFT ORCL".split(): Final codeįollowing is the complete code to get the Get current stock price in Python: import requestsĭef stock_price(symbol: str = "AAPL") -> str: The return value of the stock_price function is the current stock price. The attribute, in this case, is the class we passed above.Īfter finding the div with the specified class, we get the first span element and retrieve the text content. ![]() The find method takes two arguments, the HTML tag name we are searching for and the attribute. Return soup.find("div", class_=class_).find("span").text The stock price is in a span element nested within a div with the class: " My(6px) Pos(r) smartphoneMt(6px) W(100%)". The corresponding code is on the elements tab. We can hover through the page and select the elements as needed.
0 Comments
Leave a Reply. |