使用 Selenium 后,我决定尝试一下,undetected-chromedriver所以我使用它安装了它
pip install undetected-chromedriver
Run Code Online (Sandbox Code Playgroud)
但是,运行这个简单的脚本
import undetected_chromedriver.v2 as uc
options = uc.ChromeOptions()
options.add_argument('--no-sandbox')
driver = uc.Chrome(options=options)
with driver:
driver.get('https://google.com')
Run Code Online (Sandbox Code Playgroud)
给出错误
selenium.common.exceptions.WebDriverException:消息:未知错误:无法从无法访问的 chrome 连接到 127.0.0.1:37541 的 chrome
使用常规 Selenium 没有问题
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument("--no-sandbox"); # Bypass OS security model
driver = webdriver.Chrome(options=options)
with driver:
driver.get('https://google.com')
Run Code Online (Sandbox Code Playgroud)
这是回溯
Traceback (most recent call last):
File "/root/test-bot/src/test.py", line 6, in <module>
driver = uc.Chrome()
File "/root/anaconda3/envs/test/lib/python3.9/site-packages/undetected_chromedriver/v2.py", line 302, in __init__
super(Chrome, self).__init__(
File "/root/anaconda3/envs/test/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py", line 69, …Run Code Online (Sandbox Code Playgroud) python selenium web-scraping selenium-chromedriver undetected-chromedriver
我在尝试使用 chrome 驱动程序和 selenium 访问网站 (bet365.com) 时遇到一些麻烦(我完全被“阻止”)。
我可以使用普通的 chrome 访问该网站,但是当我尝试使用 chrome 驱动程序时,它不起作用。
我之前遇到过这个问题,并使用以下一些选项纠正了它(python):
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options, executable_path=r'PATH_TO\chromedriver.exe')
driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
"source": """
Object.defineProperty(navigator, 'webdriver', {
get: () => undefined
})
"""
})
driver.execute_cdp_cmd("Network.enable", {})
driver.execute_cdp_cmd('Network.setUserAgentOverride', {"userAgent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.53 Safari/537.36'})
driver.get("https://www.bet365.com/")
Run Code Online (Sandbox Code Playgroud)
现在,问题又回来了,这段代码不再能够绕过保护。有人能帮我吗?
python selenium google-chrome selenium-chromedriver undetected-chromedriver
有一个使用 selenium 和 chromedriver 运行一些抓取工具的 python 脚本。
几年来一直在抓取相同的网站,没有出现任何问题。从昨晚开始,通过 chromedriver 加载时,相同的网站开始加载速度非常慢,尽管在我的常规非自动化浏览器上加载完全没问题。我尝试过卸载并重新安装chromedriver、升级、重新启动等,但均无济于事。这种情况发生在两个完全独立的站点上,两个站点从昨晚开始都变得缓慢。我没有被阻止访问这些网站,但它们的加载速度比其他网站慢得多。
这几乎感觉像是一个内存分配问题,因为即使是 javascript 和滚动的执行速度也比以前慢得多。但我没有更改任何代码,即使没有更新 chromedriver,问题也会出现(以前在 112 上很快,但昨晚在版本 112 上变得很慢)。
使用 Selenium 4.2.0 和 ChromeDriver 113.0.5672.63,尽管我昨天使用的是版本 112,但仍然看到错误。
有谁知道是否发生了广泛的变化或我不知道的事情?
python selenium-chromedriver selenium-webdriver undetected-chromedriver
我正在使用 Python 包未检测到的 Chromedriver,因为我需要能够使用 webdriver 登录 Google 帐户,并且我想将选项传递{"credentials_enable_service": False, "profile.password_manager_enabled": False}给驱动程序,这样它就不会弹出保存密码的弹出窗口。我试图使用以下方法传递这些选项:
import undetected_chromedriver.v2 as uc
uc_options = uc.ChromeOptions()
uc_options.add_argument("--start-maximized")
uc_options.add_experimental_option("prefs", {"credentials_enable_service": False, "profile.password_manager_enabled": False})
driver2 = uc.Chrome(options=uc_options)
Run Code Online (Sandbox Code Playgroud)
这个参数--start-maximized工作得很好,如果我运行代码,它就会按预期最大化。但是,当添加实验选项并运行代码时,它会返回错误:
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: cannot parse capability: goog:chromeOptions
from invalid argument: unrecognized chrome option: prefs
Run Code Online (Sandbox Code Playgroud)
所以我想我应该尝试将参数作为所需的功能传递,从而编写代码:
import undetected_chromedriver.v2 as uc
uc_options = uc.ChromeOptions()
uc_options.add_argument("--start-maximized")
uc_options.add_experimental_option("prefs", {"credentials_enable_service": False, "profile.password_manager_enabled": False})
uc_caps = uc_options.to_capabilities()
driver2 = uc.Chrome(desired_capabilities=uc_caps)
Run Code Online (Sandbox Code Playgroud)
虽然此代码运行并且不会生成任何错误,但它也根本不执行任何操作。密码弹出窗口仍然显示,驱动程序甚至没有启动最大化,尽管后一部分可以作为一个选项。
所以我的问题是:如何正确地将所需的功能传递给未检测到的 Chromedriver?或者,或者:如何正确地将实验选项传递给未检测到的 Chromedriver?
python selenium python-3.x selenium-webdriver undetected-chromedriver
我以这种方式添加 chrome 选项,如果我使用代理 ip 身份验证,它就可以工作。
options = webdriver.ChromeOptions()
options.headless = True
options.add_argument('--proxy-server=92.128.165.143:3399')
driver = uc.Chrome(options=options)
Run Code Online (Sandbox Code Playgroud)
但是,我有一个具有以下格式身份验证的代理:
http://username:password@91.92.128.165.143:3399
如果我添加它就像
options.add_argument('--proxy-server=http://username:password@91.92.128.165.143:3399')
Run Code Online (Sandbox Code Playgroud)
它不起作用。我如何使用用户名/密码添加它?这仅适用于未检测到的 Chrome 驱动程序。
proxy selenium selenium-chromedriver undetected-chromedriver
我想使用 chromedriver 从 fanfiction.net 上抓取一些故事。我尝试以下操作:
from selenium import webdriver
import time
path = 'D:\chromedriver\chromedriver.exe'
browser = webdriver.Chrome(path)
url1 = 'https://www.fanfiction.net/s/8832472'
url2 = 'https://www.fanfiction.net/s/5218118'
browser.get(url1)
time.sleep(5)
browser.get(url2)
Run Code Online (Sandbox Code Playgroud)
第一个链接打开(有时我必须等待 5 秒钟)。当我想加载第二个网址时,cloudflare 介入并希望我解决验证码 - 这是无法解决的,至少 cloudflare 无法识别这一点。如果我在 chromedriver 中手动输入链接(因此在 GUI 中),也会发生这种情况。但是,如果我在普通 Chrome 中执行相同的操作,一切都会正常运行(我什至没有得到第一个链接的等待期) - 即使在私人模式下并且所有 cookie 都被删除。我可以在几台机器上重现这个。现在我的问题是:根据我的直觉,chromedriver 只是允许控制的普通 Chrome 浏览器。与普通 chrome 有什么区别,Cloudflare 如何区分两者,以及如何将我的 chromedriver 屏蔽为普通 chrome?(我不打算在很短的时间内加载很多页面,所以它不应该看起来像一个机器人)。我希望我的问题很清楚
selenium python-3.x cloudflare selenium-chromedriver undetected-chromedriver
Exception ignored in: <function Chrome.__del__ at 0x00000241BFF44360>
Traceback (most recent call last):
File "C:\Users\kevin\AppData\Local\Programs\Python\Python311\Lib\site-packages\undetected_chromedriver\__init__.py", line 769, in __del__
File "C:\Users\kevin\AppData\Local\Programs\Python\Python311\Lib\site-packages\undetected_chromedriver\__init__.py", line 758, in quit
OSError: [WinError 6] The handle is invalid
Run Code Online (Sandbox Code Playgroud)
代码通过 python 控制台运行没有错误,我只是想知道是否有办法在不通过 python 控制台运行的情况下运行代码。我的python版本是3.1.1.,Chrome是最新版本,未检测到的chrome驱动程序也是最新版本。
import undetected_chromedriver.v2 as uc
driver = uc.Chrome()
driver.get('https://nowsecure.nl')
Run Code Online (Sandbox Code Playgroud)
这是我从未检测到的 chromedriver github 找到的代码。
selenium python-3.x selenium-webdriver undetected-chromedriver
当尝试运行 unDetected-chromedriver 时,我遇到了以下错误:
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate
Run Code Online (Sandbox Code Playgroud) undetected_chromedriver我在使用版本时遇到一些问题Chromium: 116.0.5845.96。这个问题今天才开始,我几乎尝试了我能想到的所有方法,从重新安装模块,到重新安装浏览器,甚至使用version_main=116应该修复它的参数进行测试,但似乎version_main只适用于114.
这是我的代码。
import undetected_chromedriver as uc
driver = uc.Chrome()
driver.get('https://www.example.com')
Run Code Online (Sandbox Code Playgroud)
这是在 Chrome 版本 : 上启动的Version 116.0.5845.97 (Official Build) (64-bit),在控制台中返回此错误。from session not created: This version of ChromeDriver only supports Chrome version 114 Current browser version is 116.0.5845.97
当我运行 Python Selenium 脚本打开网页时出现错误。我尝试卸载并重新安装 selenium、chromeautoinstaller 和未检测到的 chromedriver。我也尝试添加option.add_argument('--headless'). 这些都没有成功,错误仍然存在。
这是我的代码:
def driverInit():
option = uc.ChromeOptions()
option.add_argument("--log-level=3")
prefs = {"credentials_enable_service": False,
"profile.password_manager_enabled": False,
"profile.default_content_setting_values.notifications": 2
}
option.add_experimental_option("prefs", prefs)
driverr = uc.Chrome(options=option)
return driverr
def driverInitBuffMarket():
option = uc.ChromeOptions()
option.add_argument(
rf'--user-data-dir=C:\Users\{os.getlogin()}\AppData\Local\Google\ChromeBuff\User Data') # e.g. C:\Users\You\AppData\Local\Google\Chrome\User Data
option.add_argument(r'--profile-directory=Default')
driverr = uc.Chrome(options=option)
return driver
Run Code Online (Sandbox Code Playgroud)
错误发生在倒数第二行,driverr = uc.Chrome(options=option)
这是错误:
Traceback (most recent call last):
File "C:\Users\kumpd\OneDrive\Desktop\All Market Bots\BuffMarket Purchase Bot Testing\main.py", line 266, in <module>
start_buy_monitoring()
File "C:\Users\kumpd\OneDrive\Desktop\All Market Bots\BuffMarket Purchase Bot Testing\main.py", …Run Code Online (Sandbox Code Playgroud) python google-chrome selenium-chromedriver selenium-webdriver undetected-chromedriver
我一直在 Synology NAS 上使用https://hub.docker.com/r/selenium/standalone-chrome,以使用 Selenium Webdriver 执行自动请求。
我不记得我运行的命令,但我启动了容器并driver = webdriver.Remote("http://127.0.0.1:4444/wd/hub")在 Python 中运行以连接到 selenium chrome 图像。
但是我有一个用例需要我使用unDetected-chromedriver。如何安装https://hub.docker.com/r/bruvv/undetected_chromedriver之类的东西并从 NAS 的 python 终端连接到它?
我只需要像这样从 python 启动 chromedriver :
import undetected_chromedriver as uc
from selenium import webdriver
options = webdriver.ChromeOptions()
driver = uc.Chrome()
driver.get('https://accounts.stockx.com/login')
print("Chrome started")
Run Code Online (Sandbox Code Playgroud)
我的 C# 程序有 100000 行代码,没有时间将所有内容重写为 C#。
我必须像上面显示的代码一样打开 chromedriver。我需要从 C# 代码访问此 chromedriver。我怎样才能做到这一点?
在 C# 中我只是这样做:
ChromeDriver driver;
var chromeOptions = new ChromeOptions();
driver = new ChromeDriver(chromeDriverService,chromeOptions);
Run Code Online (Sandbox Code Playgroud)
问题是:我如何通过 python 启动 chromedriver,然后从 c# 访问该驱动程序?我需要它,因为来自 python 的 chromedriver 无法被验证码检测到。感谢您的进步!
c# python selenium selenium-chromedriver undetected-chromedriver
import undetected_chromedriver as uc
driver = uc.Chrome()
Run Code Online (Sandbox Code Playgroud)
谷歌浏览器更新后,未检测到的 Chromedriver 无法工作。我无法使用普通的 chromedriver 作为某些块访问请提供一些解决方案,这与 chrome 更新有关吗,现在该怎么办?
请参阅以下错误 -
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\imdec\AppData\Local\Programs\Python\Python310\lib\multiprocessing\spawn.py", line 116, in spawn_main
exitcode = _main(fd, parent_sentinel)
File "C:\Users\imdec\AppData\Local\Programs\Python\Python310\lib\multiprocessing\spawn.py", line 125, in _main
prepare(preparation_data)
File "C:\Users\imdec\AppData\Local\Programs\Python\Python310\lib\multiprocessing\spawn.py", line 236, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "C:\Users\imdec\AppData\Local\Programs\Python\Python310\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path
main_content = runpy.run_path(main_path,
File "C:\Users\imdec\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 269, in run_path
return _run_module_code(code, init_globals, run_name,
File "C:\Users\imdec\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 96, in _run_module_code
_run_code(code, mod_globals, init_globals,
File …Run Code Online (Sandbox Code Playgroud) python selenium multiprocessing selenium-chromedriver undetected-chromedriver
python ×10
selenium ×9
python-3.x ×4
c# ×1
cloudflare ×1
docker ×1
macos ×1
proxy ×1
web-scraping ×1