您好,当使用python和selenium时,我在通过cloudflare访问使用DDos保护的站点时遇到问题

2024-04-26 04:53:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我计划在一个网站上建立一个自动化进程。但是,当我试图使用selenium访问站点时,无法通过消息“在访问sit之前检查浏览器。否”。消息来自cloudflare

我一直在尝试我在这里找到的一些代码,但它不起作用

1.
from selenium import webdriver
url = 'https://www.sit.no/'
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options)
driver.get(url)

2. 
from selenium import webdriver
url = 'https://www.sit.no/'
options = webdriver.ChromeOptions()
options.add_argument("--disable-blink-features=AutomationControlled")
driver = webdriver.Chrome(options=options)
driver.get(url)

3. 
import undetected_chromedriver as uc
url = 'https://www.sit.no/'
driver= uc.Chrome()
driver.get(url)

Tags: nofromhttpsimportadd消息urlget
1条回答
网友
1楼 · 发布于 2024-04-26 04:53:47
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

import subprocess
#other imports

subprocess.Popen(
    '"C:\\Program Files\\yourpathtochrome\\chrome.exe"  remote-debugging-port=9222', shell=True)

options = webdriver.ChromeOptions()
options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")

driver = webdriver.Chrome(options=options)
driver.maximize_window()
driver.get('https://www.sit.no/')

input()

首先手动打开网站并完成浏览器检查。现在关闭所有chrome浏览器,并用chrome.exe路径替换该路径。这就行了,

相关问题 更多 >