以下代码仅返回第一个游戏。我想把第5周的所有游戏和台词都放到一个数据框中。提前谢谢
import pandas as pd # library for data analysis
import requests # library to handle requests
from bs4 import BeautifulSoup # library to parse HTML documents
# get the response in the form of html
url="https://www.espn.com/nfl/lines"
response=requests.get(url)
# parse data from the html into a beautifulsoup object
soup = BeautifulSoup(response.text,'html.parser')
indiatable=soup.find('section',{'class':"Card"})
df=pd.read_html(str(indiatable))
# convert list to dataframe
df=pd.DataFrame(df[0])
print(df.head())
df
9:30 AM REC (ATS) LINE OPEN ML FPI
0 New York Jets 1-3 (1-3-0) 45.0 43.5 130 42.8%
1 Atlanta Falcons 1-3 (1-3-0) -2.5 -2.5 -150 56.9%
Out[85]:
9:30 AM REC (ATS) LINE OPEN ML FPI
0 New York Jets 1-3 (1-3-0) 45.0 43.5 130 42.8%
1 Atlanta Falcons 1-3 (1-3-0) -2.5 -2.5 -150 56.9%
您只能为此使用熊猫:
dfs
-数据帧列表要在单个数据帧上合并,请执行以下操作:
可以使用API调用获取您正在查找的数据
只需迭代响应并构建df
见下文
相关问题 更多 >
编程相关推荐