在这件事上我真的被难住了一阵子
链接到表=https://en.wikipedia.org/wiki/List_of_Manchester_United_F.C._seasons
我想从下面红色高亮的列中提取数据
然后把它放在这样的数据框中
这是我的密码
import urllib.request
url = "https://en.wikipedia.org/wiki/List_of_Manchester_United_F.C._seasons"
page = urllib.request.urlopen(url)
from bs4 import BeautifulSoup
soup = BeautifulSoup(page, "lxml")
# print(soup.prettify())
my_table = soup.find('table', {'class':'wikitable sortable'})
season = []
data = []
for row in my_table.find_all('tr'):
s = row.find('th')
season.append(s)
d = row.find('td')
data.append(d)
import pandas as pd
c = {'Season': season, 'Data': data}
df = pd.DataFrame(c)
df
你就快到了,虽然你并不需要美丽的团队;只有熊猫
试试这个:
输出:
等等,你可以从那里开始
相关问题 更多 >
编程相关推荐