【发布时间】:2021-03-23 02:31:08
【问题描述】:
我正在尝试使用selenium 在python 中抓取一个页面,以获取来自英格兰超级联赛的梦幻足球数据。我已经取得了部分成功,因为我从第一页获取了数据,但是,我需要能够单击一个按钮来获取其余玩家的数据。
为了找到这个按钮,我使用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"
【问题讨论】:
-
“但是我的代码找不到类名,当我进入我的代码的页面源时,它并没有显示这个按钮类存在”。如果它根本不在源代码中,您希望它如何工作。
-
它在实际页面的源中。当我进入我抓取页面的“驱动程序”的详细信息时,它没有显示按钮
标签: html python-3.x selenium web-scraping