Reputation: 2303
I am getting an error of urllib.error.HTTPError: HTTP Error 404: Not Found.
I feel like f-string should work for the url but it is not how would I fix this?
import pandas as pd
stockslist = ['f','goog', 'aapl']
for s in stockslist:
url = f'https://finance.yahoo.com/quote/{s}/'
print(url)
tablelist = pd.read_html(url, flavor='html5lib')
df = pd.concat(tablelist[:2])
print(df)
Upvotes: 0
Views: 683
Reputation: 522
you have to parse html first then read it
try it:
import pandas as pd
import requests
stockslist = ['f','goog', 'aapl']
for s in stockslist:
print(s)
url = f'https://finance.yahoo.com/quote/{s}/'
html = requests.get(url).content
tablelist = pd.read_html(html, flavor='html5lib')
df = pd.concat(tablelist[:2])
print(df)
Upvotes: 3