一个正在进行的项目...由python新手开发!!我已经从学校网站创建了4个“类'bs4.element.ResultSet”,称为游戏(胜利),平局,平局和习惯。我通过取消所有学校成绩并汇总来帮助联盟。我不知道如何将这4个element.resultsets组合到一起,以便我可以运行程序的其余部分。现在,它仅将“游戏(获胜)”保存到excel电子表格中。同样在下面的输出中有大量的空格-我如何摆脱那些\ n \ t?在此先感谢您的帮助。
from bs4 import BeautifulSoup as bs
import requests
import pandas as pd
import re
url = 'https://www.loomischaffee.org/athletics/teams/fall/soccer-boys/varsity'
page = requests.get(url)
soup = bs(page.content,'html.parser')
week = soup.find(id='fsEl_5138')
games = week.find_all(class_ ='fsResultWin')
draws = week.find_all(class_ ='fsResultTie')
ties = week.find_all(class_ ='fsResultLoss')
custom = week.find_all(class_ ='fsResultCustom')
# now creating 6 lists of the data contained in the above.
date = [games.find(class_ = 'fsDate').get_text() for games in games]
time = [games.find(class_ = 'fsTime').get_text() for games in games]
opponent = [games.find(class_ = 'fsAthleticsOpponentName').get_text() for games in games]
home_away = [games.find(class_ = 'fsAthleticsAdvantage').get_text() for games in games]
location = [games.find(class_ = 'fsAthleticsLocations').get_text() for games in games]
result = [games.find(class_ = 'fsAthleticsResult').get_text() for games in games]
score = [games.find(class_ = 'fsAthleticsScore').get_text() for games in games]
# now I turn data into a table using pandas so I can manipulate
results = pd.DataFrame(
{'Date': date,'Time': time,'Opponent': opponent,'Home/Away': home_away,'Location' : location,'Result': result,'Score': score,})
print(results)
results.to_excel('results.xls')