【发布时间】:2021-02-01 05:00:11
【问题描述】:
我正在尝试从网站上抓取有关前 14 名橄榄球运动员的信息(得分、铲球次数、上场时间、位置等)。 对于每个玩家,我从这个页面获得信息: http://www.lnr.fr/rugby-top-14/joueurs/nicholas-abendanon 对于每个球员,我可以轻松获得 2015-2016 赛季的信息,但我还需要 2014-2015 赛季的信息。
问题是,当我打开相应的链接 (http://www.lnr.fr/rugby-top-14/joueurs/nicholas-abendanon#season=14535) 时,源代码是相同的,我的程序抓取的信息是 2015-2016 年的数据。 即使它出现在网页上,我似乎也找不到获取前几季信息的方法。 有谁知道如何解决这个问题?
这是我作为示例给出的播放器的代码。
import bs4
from lxml import html
import requests
import string
import _pickle as pickle
from bs4 import BeautifulSoup
dic={}
url_player='http://www.lnr.fr/rugby-top-14/joueurs/nicholas-abendanon'
page = requests.get(url_player)
html=page.content
parsed_html = BeautifulSoup(html)
body=parsed_html.body
saison14_15=body.find('a',attrs={'data-title':'Saison 2014-2015'})
link=saison14_15['href']
url_season='http://www.lnr.fr/rugby-top-14/joueurs/nicholas-abendanon'+link
page_season = requests.get(url_season)
html_season=page_season.content
parsed_html_season = BeautifulSoup(html_season)
body_season=parsed_html_season.body
dic['nom']=body_season.find('h1',attrs={'id':'page-title'}).text
dic[body_season.find('span',attrs= {'class':'title'}).text]=body_season.find('span',attrs={'class':'text'}).text
info1=body_season.find('ul',attrs={'class':'infos-list small-bold'})
try:
for item in info1.findAll('li'):
dic[item.find('span',attrs={'class':'title'}).text]=item.find('span',attrs={'class':'text'}).text
info2=body_season.find('ul',attrs={'class':'fluid-block-grid-3 team-stats'})
if info2 is not None :
for item in info2.findAll('li'):
dic[item.find('span',attrs={'class':'title'}).text]=item.find('span',attrs={'class':'text'}).text
info3=body_season.find('ul',attrs={'class':'number-list small-block-grid-2'})
if info3 is not None :
for item in info3.findAll('li'):
dic[item.find('span',attrs={'class':'title'}).text]=item.find('span',attrs={'class':'text'}).text
except:
dic=dic`
【问题讨论】:
标签: python web-scraping beautifulsoup