Skip to content

Instantly share code, notes, and snippets.

@reefwing
Created March 25, 2023 22:39
Show Gist options
  • Save reefwing/708cd4ea9aba983faa55ebe4ffe6567a to your computer and use it in GitHub Desktop.
Save reefwing/708cd4ea9aba983faa55ebe4ffe6567a to your computer and use it in GitHub Desktop.
import pandas as pd
import requests
# Set the ticker value
ticker = "STW.AX"
# Define the URL to fetch data from Yahoo Finance
url = f"https://finance.yahoo.com/quote/{ticker}/history?p={ticker}"
# Send a GET request to the URL and retrieve the HTML content
response = requests.get(url)
html_content = response.content
# Use pandas to extract the data from the HTML content
df_list = pd.read_html(html_content)
# The data we want is usually the first item in the list of dataframes
df = df_list[0]
# Print the extracted data
print(df)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment