Pandas scraped a list instead of a table?

Viewed 9

I was trying to scrape the table of weather from this website:

https://www.weatherzone.com.au/station/SITE/86338/daily-summaries

As the table need to be loaded after opening the website, I import webdriver to do the job then scrape the table using pandas.

driver = webdriver.Chrome('chromedriver.exe')
driver.implicitly_wait(30)
driver.get("https://www.weatherzone.com.au/station/SITE/86338/daily-summaries")
df=pd.read_html(driver.find_element("id", "daily-summaries").get_attribute('outerHTML'))
with open("texts/test.txt", "w") as output:
    output.write(str(df))
file = open("texts/test.txt", "r")
print(file.read())

But somehow, what I scraped is a list instead of a table

[                                DATE  MIN TO 9AM(�C) ANOMALY(�C)  MAX FROM 9AM(�C) ANOMALY(�C).1  RAIN TO 9AM(mm)    Unnamed: 6
0                     Thu 01/09/2022             6.1        -2.0              16.0          -1.3              0.0           NaN
1                     Fri 02/09/2022             9.6        +1.5              12.8          -4.5              2.4           NaN
2                     Sat 03/09/2022             6.9        -1.2              14.8          -2.5              0.0           NaN
3                     Sun 04/09/2022             7.4        -0.7              12.7          -4.6              0.2           NaN
4                     Mon 05/09/2022             7.2        -0.9              16.0          -1.3              0.0           NaN
5                     Tue 06/09/2022             4.3        -3.8              17.0          -0.3              0.0           NaN
6                     Wed 07/09/2022             7.6        -0.5              20.6          +3.3              0.0           NaN
7                     Thu 08/09/2022            12.6        +4.5              17.3           0.0              3.0           NaN
8                     Fri 09/09/2022            11.1        +3.0              21.0          +3.7              0.2           NaN
9                     Sat 10/09/2022            10.9        +2.8              15.6          -1.7              6.8           NaN
10                    Sun 11/09/2022             9.6        +1.5              16.4          -0.9              0.0           NaN
11                    Mon 12/09/2022             8.6        +0.5              13.6          -3.7              1.6           NaN
12                    Tue 13/09/2022             6.4        -1.7              12.7          -4.6              1.4           NaN
13                    Wed 14/09/2022             3.5        -4.6              18.1          +0.8              0.0           NaN
14                               NaN             NaN         NaN               NaN           NaN              NaN           NaN
15            September 2022 Average             8.0        -0.1              16.0          -1.3              NaN           NaN
16       September 1855-2022 Average             8.1         NaN              17.3           NaN              NaN           NaN
17       September 1855-2022 Highest            20.5  29/09/1999              31.4    28/09/1928              NaN           NaN
18        September 1855-2022 Lowest            -0.5  03/09/1940               8.3    11/09/1969              NaN           NaN
19                               NaN             NaN         NaN               NaN           NaN              NaN           NaN
20              September 2022 Total             NaN         NaN               NaN           NaN             15.6      7 day(s)
21       Sep 1855-2022 Average Total             NaN         NaN               NaN           NaN             57.4   14.8 day(s)
22       Sep 1855-2022 Wettest Total             NaN         NaN               NaN           NaN            201.6          1916
23  Sep 1855-2022 Wettest 24hr Total             NaN         NaN               NaN           NaN             58.7    23/09/1916
24        Sep 1855-2022 Driest Total             NaN         NaN               NaN           NaN             12.0          2008
25                               NaN             NaN         NaN               NaN           NaN              NaN           NaN
26                Jan-Sep 2022 Total             NaN         NaN               NaN           NaN            401.0    103 day(s)
27   Jan-Sep 1855-2022 Average Total             NaN         NaN               NaN           NaN            459.8  113.9 day(s)]

As the text file shows above,the list only has 1 value, which is the table itself.

I can't use any function in Pandas to print the data I want.

How can I convert this list into a table again?

0 Answers
Related