我试图从这个 HTML 代码中提取“T”、“0-0”和“(2 OT)”。我开始编写下面的代码,但新手太多,无法弄清楚。谢谢你的帮助。
<div class ="sidearm-schedule-game-details flex item-1 columns"> == $0
<div class="sidearm-schedule-game-result text-italic"> == $0
<span></span>
<span>T,</span>
<span>0-0</span>
<span>(2 OT)</span>
</div>
import requests
import pandas as pd
from pandas import ExcelWriter
from bs4 import BeautifulSoup
url = 'https://lehighsports.com/sports/mens-soccer/schedule/2018'
school = requests.get(url).text
soup = BeautifulSoup(school,'lxml')
rows = soup.find_all('div',class_="sidearm-schedule-game-row flex flex-wrap flex-align-center row")
sheet = pd.DataFrame()
for row in rows:
result = row.find('div',class_="sidearm-schedule-game-result").text.strip()
df = pd.DataFrame([[result]], columns=['result'])
sheet = sheet.append(df,sort=True).reset_index(drop=True)
results.append(sheet)