Skip to content

Instantly share code, notes, and snippets.

@reefwing
Created March 25, 2023 23:46
Show Gist options
  • Save reefwing/d2e4e906f18bbc7e6c4c2abffc240e38 to your computer and use it in GitHub Desktop.
Save reefwing/d2e4e906f18bbc7e6c4c2abffc240e38 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}?p={ticker}'
# Define the header information for the request
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"}
# Send a GET request to the URL with the header information and retrieve the HTML content
response = requests.get(url, headers=headers)
html_content = response.content
# Use pandas to extract the data from the HTML content
df_list = pd.read_html(html_content)
# Print the first two items in the list of dataframes
print(df_list[0])
print(df_list[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment