小编Deb*_*anB的帖子

Selenium headless:如何使用 Selenium 绕过 Cloudflare 检测

希望专家能帮助我解开 Selenium/Cloudflare 之谜。我可以让一个网站在普通(非无头)Selenium 中加载,但无论我尝试什么,我都无法让它在无头中加载。

我已遵循 StackOverflow 帖子中的建议,例如Is there a version of Selenium WebDriver that is not detectorable? window我还查看了和对象的所有属性window.navigator,并修复了无头和非无头之间的所有差异,但不知何故仍然检测到无头。此时我非常好奇 Cloudflare 如何能够找出其中的差异。谢谢你的时间!

我尝试过的事情列表:

  • 用户代理
  • 替换cdc_为 chromedriver 中的另一个字符串
  • options.add_experimental_option("excludeSwitches", ["enable-automation"])
  • options.add_experimental_option('useAutomationExtension', False)
  • options.add_argument('--disable-blink-features=AutomationControlled')(这是让网站以非无头方式加载所必需的)
  • navigator.webdriver = undefined
  • 设置navigator.pluginsnavigator.languages、 和navigator.mimeTypes
  • window.ScreenY, window.screenTop, window.outerWidth,设置window.outerHeight为非零
  • 设置window.chromewindow.navigator.chrome
  • 将图像的宽度和高度设置为非零
  • 设置WebGL参数
  • 使固定Modernizr

重复实验

为了让网站在正常(非无头)Selenium 中加载,您必须点击_blank另一个网站的链接(以便目标网站在另一个选项卡中打开)。要复制该实验,首先创建一个包含内容的 html 文件<a href="https://poocoin.app" target="_blank">link</a>,然后在以下代码中粘贴该 html 文件的路径。

下面的版本(非无头)运行良好并加载网站,但如果您设置 …

python selenium bots webdriver selenium-webdriver

35
推荐指数
1
解决办法
6万
查看次数

Python Selenium - 获取 href 值

我正在尝试从网站复制 href 值,html 代码如下所示:

<p class="sc-eYdvao kvdWiq">
 <a href="https://www.iproperty.com.my/property/setia-eco-park/sale- 
 1653165/">Shah Alam Setia Eco Park, Setia Eco Park
 </a>
</p>
Run Code Online (Sandbox Code Playgroud)

我试过了,driver.find_elements_by_css_selector(".sc-eYdvao.kvdWiq").get_attribute("href")但它回来了'list' object has no attribute 'get_attribute'。使用driver.find_element_by_css_selector(".sc-eYdvao.kvdWiq").get_attribute("href")返回的None. 但是我不能使用 xpath,因为该网站有 20+ 个 href,我需要全部复制。使用 xpath 只会复制一个。

如果有帮助,所有 20 多个 href 都归入同一类,即sc-eYdvao kvdWiq.

最终,我想复制所有 20+ 个 href 并将它们导出到 csv 文件。

感谢任何可能的帮助。

python selenium xpath css-selectors webdriverwait

28
推荐指数
2
解决办法
5万
查看次数

无法从节点连接读取描述符:在 Windows 操作系统上使用 ChromeDriver Selenium 时,连接到系统的设备无法运行错误

我在 python 中运行 selenium webdriver 脚本时得到了这个我还在系统环境中设置了路径,并尝试下载与我的 chrome 版本匹配的 webdriver。而且也是letest版本。但我仍然收到此错误:

[8552:6856:1120/155118.770:ERROR:device_event_log_impl.cc(211)] [15:51:18.771] USB: usb_device_handle_win.cc:1020 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[8552:6856:1120/155118.774:ERROR:device_event_log_impl.cc(211)] [15:51:18.774] USB: usb_device_handle_win.cc:1020 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[8552:6856:1120/155118.821:ERROR:device_event_log_impl.cc(211)] [15:51:18.821] USB: usb_device_handle_win.cc:1020 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
Run Code Online (Sandbox Code Playgroud)

我在我的代码中使用了这个:

driver = webdriver.Chrome(resource_path("C:\\webdriver\\chromedriver.exe"))  # to open the …
Run Code Online (Sandbox Code Playgroud)

python selenium google-chrome selenium-chromedriver windows-10

28
推荐指数
4
解决办法
5万
查看次数

Selenium @FindBy vs driver.findElement()

我为什么要用@FindByvs driver.findElement()

@FindBy强迫我将所有变量移动到类级别(当大多数变量只需要在方法级别时).它似乎唯一能给我买的是我可以调用PageFactory.initElements(),它为我处理延迟初始化.

我错过了什么?

selenium annotations findby selenium-webdriver page-factory

27
推荐指数
1
解决办法
5万
查看次数

获取selenium发布的浏览器PID

我想获得selenium推出的浏览器的PID.有没有办法完成它?

selenium webdriver selenium-rc selenium-webdriver

24
推荐指数
5
解决办法
2万
查看次数

SessionNotCreatedException:消息:会话未创建:此版本的 ChromeDriver 仅支持 Chrome 版本 96 当前浏览器版本为 98.0

错误跟踪日志:

DevTools listening on ws://127.0.0.1:54791/devtools/browser/6f264bcc-d44a-40d9-b6cf- 
8b1655c97ccd
Traceback (most recent call last):
File "c:\Users\alsgn\OneDrive\desktop\mypython\getselenium\dc\findbulletins.py", line 11, in 
<module>
browser = webdriver.Chrome()
File "C:\Users\alsgn\AppData\Local\Programs\Python\Python39\lib\site- 
packages\selenium\webdriver\chrome\webdriver.py", line 70, in __init__
super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
File "C:\Users\alsgn\AppData\Local\Programs\Python\Python39\lib\site- 
packages\selenium\webdriver\chromium\webdriver.py", line 93, in __init__
RemoteWebDriver.__init__(
File "C:\Users\alsgn\AppData\Local\Programs\Python\Python39\lib\site- 
packages\selenium\webdriver\remote\webdriver.py", line 268, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\alsgn\AppData\Local\Programs\Python\Python39\lib\site- 
packages\selenium\webdriver\remote\webdriver.py", line 359, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\alsgn\AppData\Local\Programs\Python\Python39\lib\site- 
packages\selenium\webdriver\remote\webdriver.py", line 424, in execute
self.error_handler.check_response(response)
File "C:\Users\alsgn\AppData\Local\Programs\Python\Python39\lib\site- 
packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session …
Run Code Online (Sandbox Code Playgroud)

selenium google-chrome webdriver selenium-chromedriver selenium-webdriver

22
推荐指数
3
解决办法
13万
查看次数

Selenium Webdriver - 单击隐藏的元素

我正在尝试在Google云端硬盘中自动上传文件功能.

用于传递参数的元素隐藏为height - 0px.

任何用户操作都不会使此元素可见.所以我需要一个工作来点击元素不可见.

<input type="file" style="height: 0px; visibility: hidden; position: absolute; width: 340px; font-size: inherit;" multiple=""/>
Run Code Online (Sandbox Code Playgroud)

上述元素的xpath是 -

//*[@class='goog-menu goog-menu-vertical uploadmenu density-tiny']/input
Run Code Online (Sandbox Code Playgroud)

我在用

WebDriver.findElement(By.xpath(<xpath>).sendKeys(<uploadFile>)
Run Code Online (Sandbox Code Playgroud)

例外 -

org.openqa.selenium.ElementNotVisibleException
Run Code Online (Sandbox Code Playgroud)
  • 元素当前不可见,因此可能无法与之交互.

我尝试过使用JavascriptExecutor.但无法找到确切的语法.

selenium webdriver hidden-field

20
推荐指数
2
解决办法
6万
查看次数

Selenium 在 Colab 上使用 chrome 意外退出

我在 google colab 中使用 selenium chromedriver 一段时间了。
今天我开始工作,我遇到了以前从未出现过的错误。
我想知道这个错误是否与 chromedriver 版本有关。


这是今天的安装日志

!apt-get update
!apt install -y chromium-chromedriver


Get:1  focal-updates/main amd64 apparmor amd64 2.13.3-7ubuntu5.1 [494 kB]
Get:2  focal/main amd64 liblzo2-2 amd64 2.10-2 [50.8 kB]
Get:3  focal-updates/main amd64 squashfs-tools amd64 1:4.4-1ubuntu0.3 [117 kB]
Get:4  focal-updates/main amd64 snapd amd64 2.57.5+20.04ubuntu0.1 [37.6 MB]
Get:5  focal-updates/universe amd64 chromium-browser amd64 1:85.0.4183.83-0ubuntu0.20.04.2 [48.3 kB]
Get:6  focal-updates/universe amd64 chromium-chromedriver amd64 1:85.0.4183.83-0ubuntu0.20.04.2 
...
...
(Reading database ... 129791 files and directories currently installed.)
Preparing to unpack .../chromium-browser_1%3a85.0.4183.83-0ubuntu0.20.04.2_amd64.deb ... …
Run Code Online (Sandbox Code Playgroud)

selenium chromium selenium-chromedriver selenium-webdriver google-colaboratory

17
推荐指数
1
解决办法
9964
查看次数

元素MyElement在点(x,y)处不可点击...其他元素将收到点击

我正在尝试使用基于硒的Katalon Studio进行一些测试.在我的一个测试中,我必须在textarea内写.问题是我收到以下错误:

...Element MyElement is not clickable at point (x, y)... Other element would receive the click...
Run Code Online (Sandbox Code Playgroud)

事实上,我的元素位于其他可能隐藏它的diva中但是如何让click事件命中我的textarea?

java selenium webdriver selenium-webdriver katalon-studio

16
推荐指数
1
解决办法
6757
查看次数

使用Selenium自动执行测试时,如何处理调试器中暂停的叠加层

每当我尝试访问该网站并打开时我无法通过检查器检查任何元素,因为UI带有消息叠加层Paused in debugger

对此讨论最高评价和接受的回答是,要检查“源”选项卡,请检查“事件监听器断点”面板下的“鼠标”下是否设置了任何断点。我已经交叉检查了Sources-> EventListenerBreakpoint都没有设置。

对此讨论最高评价和接受的答案是检查小八角形的停止/暂停标志(在Chrome“来源”的左下角)是否为彩色(蓝色或紫色)。我不确定为什么需要对选定的网站另外执行此操作。

快照:

调试器已暂停

本次讨论中,被接受并被接受的答案是关于“ 手动步骤”的

所有解决方案似乎都指向手动过程。但是在我看来,这个问题似乎是Selenium无法做到的根本原因getPageSource()

代码试用:

System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
options.addArguments("--disable-extensions");
WebDriver driver = new ChromeDriver(options);
driver.get("http://rd.huangpuqu.sh.cn/website/html/shprd/shprd_tpxw/List/list_0.htm");
Run Code Online (Sandbox Code Playgroud)

输出:Chrome打开,但不导航到URL。

所以我的问题是:

  • 在哪种情况下会Paused in debugger发生错误?
  • 前端开发有错误吗?
  • 如何在通过自动测试过程中绕过此错误?

javascript debugging selenium breakpoints google-chrome-devtools

16
推荐指数
1
解决办法
457
查看次数