'Problem with getting a table from a website with pandas
I'm trying to get a table from a website with pd.read_html:
import requests
import pandas as pd
url = 'https://www.macrotrends.net/stocks/charts/AAPL/apple/financial-ratios?freq=Q'
html = requests.get(url).content
df_list = pd.read_html(html)
however no table is found:
ValueError: No tables found
Is there a quick remedy here, I'm not experienced with web scraping.
Thank you
Solution 1:[1]
Note: As mentioned in my comment there is no HTML table and content is generated dynamically by JavaScript - Alternatives are extract info from JavaScript or using Selenium
Another alternative, if you like to go with pandas.read_html(), is to pick the specific ressources for historic metrics stored in tables and process it in the way you like:
import requests
import pandas as pd
url = 'https://www.macrotrends.net/stocks/charts/AAPL/apple/'
metrics = ['current-ratio','ebit-margin']
for m in metrics:
html = requests.get(url+m).content
print(pd.read_html(html)[0]) #or process/store for your needs
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
