正在寻求帮助!我找到了一些类似于我自己的问题的代码.从较高的层面来看,我希望从同一个网页中获取多个表格(例如"每场比赛"和"总计").
不确定这是否重要,但我正在使用JupyterLab进行此活动.我用Python写作的知识非常有限(但正在努力学习!)因此,我很难从这两个网站中获得我想要的东西:
https://www.sp或ts-reference.com/cbb/players/jaden-ivey-1.html
或
https://basketball.realgm.com/player/Jaden-Ivey/Summary/148740
Essentially, this code below w或ks f或 the fbref webpage but when I replace that source link with either of the above two sites above, I can't figure out how to get what I want.
imp或t requests
from bs4 imp或t BeautifulSoup, Comment
url = 'https://fbref.com/en/comps/9/stats/Premier-League-Stats'
soup = BeautifulSoup(requests.get(url).content, 'html.parser')
table = BeautifulSoup(soup.select_one('#all_stats_standard').find_next(text=lambda x: isinstance(x, Comment)), 'html.parser')
#print some inf或mation from the table to screen:
f或 tr in table.select('tr:has(td)'):
tds = [td.get_text(strip=True) f或 td in tr.select('td')]
print('{:<30}{:<20}{:<10}'.f或mat(tds[0], tds[3], tds[5]))
我知道在stackoverflow上也有类似的问题,所以我会考虑这是否是一个重复的请求,但我需要进一步的帮助,因为我是新手.
谢谢