Selenium 不会抓取所有网络数据

时间:2021-03-23 02:31:08

标签: html python-3.x selenium web-scraping

我正在尝试使用 pythonselenium 中抓取一个页面,以从英格兰超级联赛中获取有关梦幻足球数据的数据。我已经取得了部分成功,因为我已经从第一页获取了数据,但是,我需要能够点击一个按钮来获取其他玩家的数据。

为了找到这个按钮,我使用了 selenium,但我的代码找不到类名。我使用“驱动程序”从页面中抓取数据,当我查看“页面源”详细信息时,没有显示该按钮,但我可以在网页的 html 中看到该按钮。下面的代码显示了我如何尝试获取按钮,但它不起作用。如果你能帮忙,谢谢。

my_url = 'https://fantasy.premierleague.com/statistics' #this is the link
option = Options()

option.headless = True #It won't open up a tab of the website
driver = webdriver.Chrome(executable_path='C://chromedriver.exe', options = option) #This goes to my chromefinder in C drive and opens the website
driver.get(my_url)
button = driver.find_element_by_class_name('PaginatorButton__Button-xqlaki-0 kRIEWN')

我要找的网站的html是:

<button type="button" class="PaginatorButton__Button-xqlaki-0 kRIEWN"

1 个答案:

答案 0 :(得分:1)

driver.find_element_by_css_selector('.PaginatorButton__Button-xqlaki-0.kRIEWN')

您实际上有多个类名,请改用 css 选择器。