This post shows how to get recent news headlines for a stock ticker using the Yahoo Finance library in Python.
First, make sure yfinance is installed with pip:
$ pip install yfinance
Note that the version needs to be recent to avoid 429 Too Many Requests errors.
You may need a version specific install, for example:
$ pip install yfinance==0.2.54
The complete code is below:
import yfinance as yf
tickerSymbol = input("Enter ticker: ")
ticker = yf.Ticker(tickerSymbol)
newsItems = ticker.news
# Take slice of the latest five.
latestFiveItems = newsItems[:5]
for item in latestFiveItems:
title = item["content"]["title"]
pubDate = item["content"]["pubDate"]
print(title)
print(pubDate)
print() # Newline.
Example run:
Enter ticker: ASML Hyperscalers Plan to Spend $700 Billion on AI This Year. These 2 Stocks Are the Biggest Beneficiaries. 2026-02-27T12:01:00Z ASML Says High-NA EUV Tools Ready for Mass Production 2026-02-27T11:43:03Z ASML's Next Tool Could Quietly Change Chipmaking 2026-02-27T11:42:13Z Is It Too Late To Consider ASML Holding (ENXTAM:ASML) After Its 77.9% One Year Surge? 2026-02-27T11:17:05Z ASML EUV Breakthrough Lifts Chip Output And Raises Valuation Questions 2026-02-27T10:11:44Z
