我正在从这个网站的https://www.iban.com/country-codes表中进行网络抓取,但是当把它放到DataFrame中时,抓取的信息是不完整的。
# Webscrape list of official countries with country codes
url = 'https://www.iban.com/country-codes'
response = requests.get(url)
page = response.content
scraping = BeautifulSoup(page, "lxml")
scraping
element = scraping.find("table", attrs={"class" : "table table-bordered downloads tablesorter"})
df = pd.read_html(str(element))
countrycodes = df[0]因此,例如:菲律宾( the )、大不列颠及北爱尔兰联合王国(the)、瑞士等国家不在数据框架中。
发布于 2020-06-14 00:41:44
数据在DataFrame中。当您将countrycodes打印到屏幕上时,pandas将缩短数据帧并放置...而不是行。
为了演示,此代码将加载表并将其保存到CSV:
import pandas as pd
df = pd.read_html('https://www.iban.com/country-codes')[0]
df.to_csv('data.csv')生成此CSV (突出显示的是"Philippines (the)"):

https://stackoverflow.com/questions/62362253
复制相似问题