我需要从iana.org的顶级域名刮刮表。
我的代码:
import requests
from bs4 import BeautifulSoup
URL = 'https://www.iana.org/domains/root/db'
page = requests.get(URL)
soup = BeautifulSoup(page.content, 'html.parser')
results = soup.find(id='tld-table')我怎样才能得到这一点,熊猫DataFrame的结构,因为它是在网站(域名,类型,TLD管理器)。
发布于 2021-05-06 23:18:13
BeautifulSoup已经提供了一些可以读取表格的东西,不需要使用Pandas:
import pandas as pd
url = "https://www.iana.org/domains/root/db"
# This returns a list of DataFrames with all tables in the page.
df = pd.read_html(url)[0]发布于 2021-05-06 23:20:48
您可以使用pandas pd.read_html
import pandas as pd
URL = "https://www.iana.org/domains/root/db"
df = pd.read_html(URL)[0]
print(df.head())
Domain Type TLD Manager
0 .aaa generic American Automobile Association, Inc.
1 .aarp generic AARP
2 .abarth generic Fiat Chrysler Automobiles N.V.
3 .abb generic ABB Ltd
4 .abbott generic Abbott Laboratories, Inc.https://stackoverflow.com/questions/67421077
复制相似问题