【发布时间】:2020-03-08 11:15:19
【问题描述】:
Python 和网络抓取的新手。我正在尝试通过 BeautifulSoup(来自 ESPN)将现场大学橄榄球比分导入 Panda DataFrame。我搜索了高低,似乎无法正确格式化导入的分数。
一旦我将它放入数据框中,我会将结果导入 Excel。
这是我目前所拥有的。结果在一列中显示所有团队,然后是所有分数。
from bs4 import BeautifulSoup
from selenium import webdriver
import pandas as pd
driver = webdriver.Chrome(executable_path=r'C:\Users\Jims Maximus Hero\Desktop\chromedriver.exe')
driver.get("https://www.espn.com/college-football/scoreboard/_/group/80/year/2019/seasontype/2/week/11")
html = driver.page_source
soup = BeautifulSoup(html, "lxml")
for tag in soup.find_all("span", {"class":"sb-team-short"}):
print (tag.text)
for tag in soup.find_all("td", {"class":"total"}):
print (tag.text)
感谢您的帮助
【问题讨论】:
-
拥有
page_source后,您是否尝试过使用pd.read_html()并以这种方式提取表格?看来您还可以使用{'class': 'scoreboard-wrapper'}定位某些 div -
感谢您的帮助。明天我会修改并回复你。我正在学习。
标签: python pandas selenium beautifulsoup