Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
293 views
in Technique[技术] by (71.8m points)

python - How can i eliminate the "accept cookies" popup that blocking the content of webpage?

I already spend a week trying to figure out how to dismiss the "accept cookies" popup that keeps freezing my code.I borrowed the code from here and transformed it a bit to meet my needs.I searched the site but almost nothing to seem like my case.I m posting the portion of the code that causes the problem.Any help will be appreciated.

from selenium import webdriver
from selenium.webdriver.opera.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from time import sleep
from datetime import datetime
import pandas as pd

errors = []
season = []


for id in range(2124889, 2124890):
# Opening the connection and grabbing the page
my_url = f'https://www.lefigaro.fr/sports/football/live/bundesliga/2020/{id}/*'
option = Options()
option.headless = False
driver = webdriver.Opera(options=option)
driver.get(my_url)
driver.maximize_window()
WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((
        By.XPATH,'//iframe[@id="appconsent"]')))
WebDriverWait(driver,10).until(EC.element_to_be_clickable((
        By.XPATH,'//button[contains(@title,"Tout Accepter")]'))).click()
sleep(5)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Instead of

WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((
        By.XPATH,'//iframe[@id="appconsent"]')))
WebDriverWait(driver,10).until(EC.element_to_be_clickable((
        By.XPATH,'//button[contains(@title,"Tout Accepter")]'))).click()

Use this

WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((
        By.XPATH,"//div[@id='appconsent']//iframe")))
WebDriverWait(driver,10).until(EC.visibility_of_element_located((
        By.CSS_SELECTOR,'button.button__acceptAll'))).click()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...