requests Fails for Yahoo Finance
Yahoo Finance loads the historical price table using JavaScript.
When we use requests, Python only downloads the initial HTML —
it does not execute JavaScript.
So the historical table you see in the browser is missing in the downloaded HTML.
Selenium opens a real browser (Chrome), executes JavaScript, and lets us interact with dynamically loaded content.
This version prints the fully loaded HTML (driver.page_source).
Next step is extracting the History table rows.
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from time import sleep
# ---------- INPUT ----------
stockurl = "https://finance.yahoo.com/quote/RELIANCE.NS/history"
# ---------- DRIVER ----------
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
try:
driver.get(stockurl)
# Wait for JavaScript-loaded content
sleep(5)
# ---------- DATA ----------
html = driver.page_source
print(html)
finally:
# Always close the browser safely
driver.quit()