无法使用python单击包含href=javascript void的load more按钮

无法使用python单击包含href=javascript void的load more按钮,python,selenium,Python,Selenium,我正在尝试从网页“”提取所有URL数据此网站包含“加载更多”按钮,可加载更多页面。 我尝试了下面的代码,通过单击“加载更多”按钮,首先加载所有页面 from selenium.webdriver.support.ui import WebDriverWait as wait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By fro

我正在尝试从网页“”提取所有URL数据此网站包含“加载更多”按钮,可加载更多页面。 我尝试了下面的代码,通过单击“加载更多”按钮,首先加载所有页面

from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains

driver = webdriver.Chrome()
driver.get("https://careers.wipro.com/search-for-jobs.aspx?div=Technologies&#divhere")

main_menu = driver.find_element_by_css_selector('#DivVeiwMore .button-show-more').click()

actions = ActionChains(driver)
actions.move_to_element(main_menu).click().build().perform()
上面的代码给出了以下错误

元素ClickInterceptedException:消息:元素ClickIntercepted:元素。。。在点(455863)处不可单击。其他因素会

然后我尝试使用下面的代码

url = "https://careers.wipro.com/search-for-jobs.aspx? 
div=Technologies&#divhere"
driver = webdriver.Chrome()
driver.get(url)
html = driver.page_source.encode('utf-8')
page_num = 0

while driver.find_elements_by_css_selector('#DivVeiwMore .button-show-more'):
element = driver.find_element_by_css_selector('#DivVeiwMore .button-show-more').click()
driver.execute_script("arguments[0].click();", element)
page_num += 1
print("getting page number" +str(page_num))
time.sleep(10)
html=驱动程序.page\u源代码('utf-8') 上面的代码给了我另一个错误 元素ClickInterceptedException:消息:元素ClickIntercepted:元素。。。在点(455863)处不可单击。其他元素将收到单击:。。。 (会话信息:chrome=81.0.4044.138)

然后我尝试使用wait,但效果不好。请在下面查找代码和错误

from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains

driver = webdriver.Chrome()
driver.get("https://careers.wipro.com/search-for-jobs.aspx? 
div=Technologies&#divhere")

main_menu = 
driver.find_element_by_css_selector('a[href="javascript:void(0);"]').click()

#actions = ActionChains(driver)
#actions.move_to_element(main_menu).click().build().perform()

wait(driver, 15).until(EC.element_to_be_clickable((By.CSS_SELECTOR, 
'a[href="javascript:void(0);"]'))).click()
这给了我一个错误 ElementNotInteractiableException:消息:元素不可交互


我不确定哪里出了问题。有人能帮我单击“加载更多”按钮并加载所有页面,这样我就可以从页面中提取所有href元素。

观察到接受cookie的通知中断了单击,而您没有等待加载元素

有不同的方法,但我使用了1个Webdriverwait。 检查以下行是否适合您

更改驱动程序路径

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
import time

opt=webdriver.ChromeOptions()

opt.add_argument("--start-maximized")

driver= webdriver.Chrome(executable_path="C:\\chrome driver\\chromedriver.exe",options=opt)
driver.get("https://careers.wipro.com/search-for-jobs.aspx?div=Technologies&#divhere")

# if Accept cookie and decline cookie notification is visible in 5 sec then click on decline 
try:
    WebDriverWait(driver,5).until(EC.element_to_be_clickable((By.XPATH,'//*[@id="DivCookie"]/div/div/div/a[2]/button')))
    driver.find_element_by_xpath('//*[@id="DivCookie"]/div/div/div/a[2]/button').click()
except TimeoutException:
    pass

WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.CSS_SELECTOR, '#DivVeiwMore .button-show-more')))
time.sleep(1) # just to ensure element is properly loaded
main_menu = driver.find_element_by_css_selector('#DivVeiwMore .button-show-more').click()
# you can use Action chain as well

所观察到的是,接受cookie的通知中断了单击,并且您没有等待加载元素

有不同的方法,但我使用了1个Webdriverwait。 检查以下行是否适合您

更改驱动程序路径

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
import time

opt=webdriver.ChromeOptions()

opt.add_argument("--start-maximized")

driver= webdriver.Chrome(executable_path="C:\\chrome driver\\chromedriver.exe",options=opt)
driver.get("https://careers.wipro.com/search-for-jobs.aspx?div=Technologies&#divhere")

# if Accept cookie and decline cookie notification is visible in 5 sec then click on decline 
try:
    WebDriverWait(driver,5).until(EC.element_to_be_clickable((By.XPATH,'//*[@id="DivCookie"]/div/div/div/a[2]/button')))
    driver.find_element_by_xpath('//*[@id="DivCookie"]/div/div/div/a[2]/button').click()
except TimeoutException:
    pass

WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.CSS_SELECTOR, '#DivVeiwMore .button-show-more')))
time.sleep(1) # just to ensure element is properly loaded
main_menu = driver.find_element_by_css_selector('#DivVeiwMore .button-show-more').click()
# you can use Action chain as well

是的,它成功了,非常感谢您的帮助。您是如何找到cookie元素的xpath的??在chrome中右键单击该元素,将鼠标悬停在copy上。。。你也可以在谷歌上搜索…标记答案如果它解决了问题,有一个正确的标志…你知道如何处理显示“我拒绝”按钮的网页,但我只是接受了一个像我附加的截图一样的页面吗?它将在5秒后自动通过。。。。通过尝试和除块…因此,如果它是可见的,它将下降,如果不是,它将继续等待5分钟..是的,它工作了,非常感谢您的帮助。您如何找到cookie元素的xpath?在chrome中右键单击该元素,将鼠标悬停在副本上。。。你也可以在谷歌上搜索…标记答案如果它解决了问题,有一个正确的标志…你知道如何处理显示“我拒绝”按钮的网页,但我只是接受了一个像我附加的截图一样的页面吗?它将在5秒后自动通过。。。。通过尝试和除块…因此,如果它是可见的,它将下降,如果不是,它将继续等待5分钟。。