pandas.read_html returns wrong table contents

I try to scrape two tables (assets and liabilities) from :

https://www.marketwatch.com/investing/stock/aapl/financials/balance-sheet

The first table looks like this: enter image description here

Following is my code:

tables = pd.read_html("https://www.marketwatch.com/investing/stock/spg/financials/balance-sheet")

enter image description here

As you can see, the scraped table is completely wrong.

How could I scrape the table correctly?

Thank you in advance for any help:-)

Answer

let’s look at selenium for this one, you might be able to do it with bs4 and some fun request stuff

from selenium import webdriver
import time

url = "https://www.marketwatch.com/investing/stock/spg/financials/balance-sheet"
driver = webdriver.Firefox()
driver.get(url)
time.sleep(10)
tables = driver.find_elements_by_class_name("table")

tables[3].text.splitlines() # this looks to split the new line characters
tables[4].text.splitlines()

after that I think you could assign key value pairs and make a dataframe that way, or use numpy