Python 3.x 内容聚合器
我正在从skysports网站上搜集所有欧洲顶级足球排行榜的数据。我能够用pandas获得数据框,但除了使用csv文件外,我找不到在html上显示表格的解决方案。有没有其他方法或者我必须使用不同的技术?谢谢你Python 3.x 内容聚合器,python-3.x,django,Python 3.x,Django,我正在从skysports网站上搜集所有欧洲顶级足球排行榜的数据。我能够用pandas获得数据框,但除了使用csv文件外,我找不到在html上显示表格的解决方案。有没有其他方法或者我必须使用不同的技术?谢谢你 page = [ 'https://www.skysports.com/premier-league-table', 'https://www.skysports.com/la-liga-table', 'https://www.skysports.co
page = [
'https://www.skysports.com/premier-league-table',
'https://www.skysports.com/la-liga-table',
'https://www.skysports.com/bundesliga-table',
'https://www.skysports.com/serie-a-table',
'https://www.skysports.com/ligue-1-table'
]
league = [ "epl", "liga", "bund", "serie", "ligue", ]
for pag, leag in zip(page, league):
response = requests.get(pag)
soup = BeautifulSoup(response.text, 'html.parser')
top_col = soup.find('tr', attrs={'class': 'standing-table__row'})
columns = [col.get_text() for col in top_col.find_all('th')]
last_df = pd.DataFrame(columns=columns)
last_df
contents = soup.find_all('tr', attrs={'class':re.compile('standing-table__row')})
for content in contents:
teams = [tea.get_text().strip('\n') for tea in content.find_all('td')]
first_df = pd.DataFrame(teams, columns).T
first_df.columns=columns
last_df = pd.concat([last_df,first_df], ignore_index=True)
last_df.to_csv('{0}.csv'.format(leag), index = False, sep=',', encoding='utf-8')
file_path = [ "EPL.csv", "LIGA.csv", "BUND.csv", "SERIE.csv", "LIGUE.csv", ]
final = []
# EPL
csv_file = open(file_path[0])
final1 = from_csv(csv_file)
#Liga
csv_file1 = open(file_path[1])
final2 = from_csv(csv_file1)
#Bund
csv_file2 = open(file_path[2])
final3 = from_csv(csv_file2)
#Serie
csv_file3 = open(file_path[3])
final4 = from_csv(csv_file3)
#Ligue
csv_file4 = open(file_path[4])
final5 = from_csv(csv_file4)
final.append(final1)
final.append(final2)
final.append(final3)
final.append(final4)
final.append(final5)
standings = {
'final': final
}