0

我使用 pandas 来抓取这个网站https://www.mapsofworld.com/lat_long/poland-lat-long.html但我只有 3 个元素。我怎样才能从表中获取所有元素?

import numpy as np
import pandas as pd

#for getting world map
import folium

# Retreiving Latitude and Longitude coordinates
info = pd.read_html("https://www.mapsofworld.com/lat_long/poland-lat-long.html",match='Augustow',skiprows=2)

#convering the table data into DataFrame
coordinates = pd.DataFrame(info[0])
data = coordinates.head()

print(data)

挑选

4

1 回答 1

1

看起来如果您安装并用作html5lib解析器,它可能会解决您的问题:

df = pd.read_html("https://www.mapsofworld.com/lat_long/poland-lat-long.html",attrs={"class":"tableizer-table"},skiprows=2,flavor="html5lib")

>>>df
[                      0         1          2
0             Locations  Latitude  Longitude
1                   NaN       NaN        NaN
2              Augustow   53°51'N    23°00'E
3    Auschwitz/Oswiecim   50°02'N    19°11'E
4       Biala Podxlaska   52°04'N    23°06'E
..                  ...       ...        ...
177           Zawiercie   50°30'N    19°24'E
178        Zdunska Wola   51°37'N    18°59'E
179           Zgorzelec   51°10'N     15°0'E
180            Zyrardow    52°3'N    20°28'E
181              Zywiec   49°42'N    19°10'E

[182 rows x 3 columns]]
于 2021-11-08T20:44:03.987 回答