因此,我正在使用selenium进行抓取,我想单击“防御”部分中的“下一步”按钮,但我编写的代码在“摘要”中单击了“下一步”。你知道吗
以下是供您尝试的url:
所以它选择了“防御”,我可以在窗口中看到它被选中,但是下一页没有出现。单击“摘要”我发现下一个函数实际上正在那里发生。你知道吗
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
browser= webdriver.Chrome(executable_path ="C:\Program Files (x86)\Google\Chrome\chromedriver.exe")
browser.get('https://www.whoscored.com/Regions/252/Tournaments/2/Seasons/7361/Stages/16368/PlayerStatistics/England-Premier-League-2018-2019')
browser.find_element_by_xpath("""//*[@id="stage-top-player-stats-options"]/li[2]/a""").click()
element = WebDriverWait(browser, 20).until(EC.presence_of_element_located((By.XPATH, """//*[@id="next"]""")))
browser.execute_script("arguments[0].click();", element)
*
,因为它会导致性能下降和元素查找时间延长document.getElementById('next').click()
之类的内容,他是否会使用鼠标假设以上所有内容,您应该在
Defensive
选项卡上找到一个唯一标识next
按钮的选择器,它类似于:参考文献:
对于每个选项卡(Summary,Defensive,…),添加相同的
id=next
到DOM的新下一步按钮。选择防御性,你会看到下一个按钮有两个相同的
id=next
,选择进攻性,下一个按钮有三个。使用基本的
id=next
选择器,您总是单击Summary选项卡中的第一个next按钮。因为您使用的是JavaScript,什么也没有发生,所以尝试使用Selenium click方法单击,您将得到一个错误。要解决此问题,请调整选择器,使其更特定于dom-
#statistics-paging-defensive #next
。你知道吗另外,当你第一次打开页面时,会出现cookies接受屏幕并阻止页面,你可以使用下面的方法跳过它。你知道吗
xpath for next按钮对此页不是唯一的。试试这个
或者
相关问题 更多 >
编程相关推荐