简体   繁体   English

WebScraping with Selenium Python 问题

[英]WebScraping with Selenium Python Question

I have this code:我有这段代码:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver import EdgeOptions
import os

os.environ['PATH'] += "C:\\Users\\czoca\\PycharmProjects\\pythonProject4\\chromedriver.exe"

driver = webdriver.Chrome()
driver.get("https://www.teintes.fr/")
driver.implicitly_wait(10)
myelement = driver.find_element(By.XPATH, "/html/body/div[6]/div[2]/div[1]/div[2]/div[2]/button[1]/p")
myelement = driver.find_element(By.NAME, "Carens III")
myelement1.click()
myelement.click()

Everything seems ok I am following some tutorials and documentation, for the XPATH and I tried other attributes..一切似乎都很好我正在遵循一些教程和文档,对于 XPATH 我尝试了其他属性..

But I have a pop up to consent to the web terms that i have to press Autorizate.但是我有一个弹出窗口同意我必须按 Autorizate 的 web 条款。 But it wont click on it.但它不会点击它。 Any ideia why?知道为什么吗? enter image description here在此处输入图像描述

It is the button "Autoriser"这是按钮“Autoriser”

You can try this:你可以试试这个:

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

driver = webdriver.Chrome()
url = 'https://www.teintes.fr/'
driver.get(url)
accept_cookies_button = WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.XPATH, "//*[text()='Autoriser']")))
accept_cookies_button.click()

Advices:忠告:

  • Use recognizables selectors使用可识别的选择器
  • It is a good tip to wait for the element you will use等待您将使用的元素是一个很好的提示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM