相关疑难解决方法(0)

如何使用Python + Selenium WebDriver保存和加载cookie

如何将Python的Selenium WebDriver中的所有cookie保存到txt文件中,然后再加载它们?该文档没有说明getCookies函数的任何内容.

python selenium webdriver

78
推荐指数
6
解决办法
9万
查看次数

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万
查看次数

如何使用 Selenium 和 Python 绕过 Google CAPTCHA?

如何使用 Selenium 和 Python 绕过 Google CAPTCHA?

当我尝试抓取某些东西时,Google 会给我一个 CAPTCHA。我可以使用 Selenium Python 绕过 Google CAPTCHA 吗?

例如,它是 Google reCAPTCHA。您可以通过此链接查看此 CAPTCHA:https : //www.google.com/recaptcha/api2/demo

python selenium captcha recaptcha selenium-chromedriver

32
推荐指数
2
解决办法
9万
查看次数

是否有无法检测到的 Selenium WebDriver 版本?

我在住宅代理网络后面的Ubuntu服务器上通过 Selenium 运行 Chrome 驱动程序。然而,我的硒正在被检测到。有没有办法让 Chrome 驱动程序和 Selenium 100% 无法检测?

我已经尝试了很长时间,但我忘记了我所做的许多事情,包括:

  1. 尝试不同版本的 Chrome
  2. 添加几个标志并从 Chrome 驱动程序文件中删除一些词。
  3. 使用隐身模式在代理(住宅代理)后面运行它。
  4. 加载配置文件。
  5. 随机鼠标移动。
  6. 随机化一切。

我正在寻找 100% 无法检测到的真正 Selenium 版本。如果那曾经存在过。或者机器人跟踪器无法检测到的另一种自动化方式。

这是浏览器启动的一部分:

sx = random.randint(1000, 1500)
sn = random.randint(3000, 4500)

display = Display(visible=0, size=(sx,sn))
display.start()


randagent = random.randint(0,len(useragents_desktop)-1)

uag = useragents_desktop[randagent]
#this is to prevent ip leaking
preferences =
    "webrtc.ip_handling_policy" : "disable_non_proxied_udp",
    "webrtc.multiple_routes_enabled": False,
    "webrtc.nonproxied_udp_enabled" : False

chrome_options.add_experimental_option("prefs", preferences)
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-impl-side-painting")
chrome_options.add_argument("--disable-setuid-sandbox")
chrome_options.add_argument("--disable-seccomp-filter-sandbox")
chrome_options.add_argument("--disable-breakpad")
chrome_options.add_argument("--disable-client-side-phishing-detection")
chrome_options.add_argument("--disable-cast")
chrome_options.add_argument("--disable-cast-streaming-hw-encoding")
chrome_options.add_argument("--disable-cloud-import")
chrome_options.add_argument("--disable-popup-blocking")
chrome_options.add_argument("--ignore-certificate-errors")
chrome_options.add_argument("--disable-session-crashed-bubble")
chrome_options.add_argument("--disable-ipv6")
chrome_options.add_argument("--allow-http-screen-capture") …
Run Code Online (Sandbox Code Playgroud)

selenium google-chrome webdriver selenium-chromedriver selenium-webdriver

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

使用Selenium扩展(Python)

我目前正在使用Selenium来运行Chrome实例以测试网页.每次我的脚本运行时,都会启动一个干净的Chrome实例(清除扩展名,书签,浏览历史记录等).我想知道是否可以使用Chrome扩展程序运行我的脚本.我已经尝试过搜索Python示例,但是当我用Google搜索时没有出现任何问题.

python selenium google-chrome selenium-webdriver

17
推荐指数
3
解决办法
2万
查看次数

无法使用Selenium自动化Chase站点登录

当我尝试使用Selenium(Python)登录Chase网站时,我遇到以下错误消息:

追逐登录失败图像

但是,使用"人"登录工作正常.似乎当Selenium找到一个元素时会引发问题.

我错过了什么吗?我试图在stackoverflow上找到答案,但无济于事.

更新:

预期的结果是脚本将成功允许我以编程方式登录.

这是下面的代码示例:

import time
import os

from selenium import webdriver

CHASE_USER_ID = os.getenv('CHASE_USER_ID', None)
CHASE_PASSWORD = os.getenv('CHASE_PASSWORD', None)

assert CHASE_USER_ID is not None, 'Chase user id not set'
assert CHASE_PASSWORD is not None, ' Chase password not set'


def main():
    chrome_options = webdriver.ChromeOptions()
    driver = webdriver.Chrome(r'./chromedriver', chrome_options=chrome_options)

    try:
        driver.get('https://secure07c.chase.com/web/auth/#/logon/logon/chaseOnline?')

        time.sleep(2)

        user_element = driver.find_element_by_id('userId-input-field')  # Finding an element here seems to make the login process fail 
        user_element.send_keys(CHASE_USER_ID)

        password_element = driver.find_element_by_id('password-input-field')
        password_element.send_keys(CHASE_PASSWORD)

        time.sleep(2)

        password_element.submit()

        time.sleep(10)
    finally:
        driver.quit()


if …
Run Code Online (Sandbox Code Playgroud)

python selenium google-chrome webdriver selenium-chromedriver

13
推荐指数
1
解决办法
1836
查看次数

Selenium 停留在“在访问 URL 之前检查您的浏览器”

这是最近的问题,我想是三四天前开始的。它并没有与我自己的系统隔离,因为我也在远程服务器(Windows 10、Windows Server)上运行该软件。它也不是孤立于任何特定 URL,因为我现在无法通过任何具有此检查的 URL。

标题:“稍等……”“在访问 URL 之前检查您的浏览器”。“这个过程是自动的。你的浏览器很快就会重定向到你请求的内容。” “请允许最多 5 秒……”“Cloudflare 的 DDos 保护”“Ray Id:xxxxxxxxxxxxxxxxxx”

  • 我尝试过不同的系统(均基于 Windows)
  • 我尝试过不同的驱动程序(壁虎和铬)
  • 我尝试了不同的网址
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('wwww.etherdelta.com')
Run Code Online (Sandbox Code Playgroud)

有谁知道我如何解决这个问题;或者是时候放下可怜的提米(程序)了吗?

python selenium

13
推荐指数
2
解决办法
1万
查看次数

有没有办法从Javascript中检测到我在Selenium Webdriver页面中

我想在我的测试中抑制TinyMCE的初始化,并且如果Javascript可以检测到我在Selenium自动化页面中运行,则可以轻松完成.

那么,是否有一些我可以用来检测Selenium驱动程序的JS代码?或者,如何扩展userAgent字符串以包含我可以从JS检测到的模式?

如果它真的很重要,我在Mac OS X上运行黄瓜和水豚.

javascript selenium webdriver cucumber capybara

12
推荐指数
2
解决办法
1万
查看次数

由于“此浏览器或应用程序可能不安全”,无法使用 selenium 自动化登录谷歌。

我正在尝试使用 selenium 登录谷歌,但不断收到“此浏览器或应用程序可能不安全”的错误消息。

我用来登录的功能是:

async function loginToChrome(driver, username, password) {
  await driver.get("https://accounts.google.com/signin");
  await driver.sleep(1000);
  let email_phone = await driver.findElement(
    By.xpath("//input[@id='identifierId']")
  );
  await email_phone.sendKeys(username);
  await driver.findElement(By.id("identifierNext")).click();
  await driver.sleep(1000);

  let passEl = await driver.findElement(By.xpath("//input[@name='password']"));
  await passEl.sendKeys(password);
  await driver.findElement(By.id("passwordNext")).click();
  await driver.sleep(1000);
}
Run Code Online (Sandbox Code Playgroud)

这是与/sf/ask/4160341741//sf/ask/4149388281/相同的问题 无法在此浏览器或应用程序中签署您可能不安全的python-selenium-chrome

我试过同时使用 chrome 和 firefox 网络驱动程序,但都不起作用。我也试过这样做.excludeSwitches(['enable-automation'])也没有帮助。

这让我想到,也许登录页面可以检测到我正在自动化环境中运行。我尝试了这个解决方案,该解决方案会隐藏应用程序正在 Web 驱动程序中运行:网站是否可以检测到您何时将 selenium 与 chromedriver 一起使用?

我还调查了这User-Agent是否是问题所在,但我发现它与我的常规 chrome 相同。

所有这些都没有奏效,这让我陷入困境。我已经看到一些解决方案说要使用正常安装的 chrome 中已经创建的用户配置文件,但这不适用于我的用例。

有没有人找到解决这个问题的方法?我一直在寻找几个小时,结果空手而归。

编辑: 这似乎最近引起了很多关注。我找到了一个解决方案,可以让我继续使用自动化客户端而不会出现太多问题。切换到 Puppeteer。看看这些包:

    "puppeteer",
    "puppeteer-extra",
    "puppeteer-extra-plugin-stealth"
Run Code Online (Sandbox Code Playgroud)

编辑 2:我最近看到这引起了很多关注。我找到了我最终用来登录的代码。我用 puppeteer 而不是 selenium …

javascript selenium google-chrome selenium-chromedriver selenium-webdriver

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

Selenium 应用程序在 Heroku 上托管时重定向到 Cloudflare 页面

我制作了一个不和谐的机器人,它使用 selenium 访问网站并获取信息,当我在本地运行代码时,我没有任何问题,但是当我部署到 Heroku 时,我得到的第一个 URL 将我重定向到 page Attention Required! | Cloudflare

我努力了:

还有许多其他具有我使用的相同设置的:

options = Options()
options.binary_location = os.environ.get("GOOGLE_CHROME_BIN")
options.add_experimental_option("excludeSwitches", ["enable-logging", "enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
options.add_argument("--disable-blink-features=AutomationControlled")
options.add_argument("--headless")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--no-sandbox")
self.driver = webdriver.Chrome(executable_path=os.environ.get("CHROMEDRIVER_PATH"), options=options)
self.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'})
Run Code Online (Sandbox Code Playgroud)

但这不起作用,代码仅在本地运行

PS:本地我在Windows上

我重定向到的页面来源: https://gist.github.com/rafalou38/9ae95bd66e86d2171fc8a45cebd9720c 页面来源

python selenium captcha heroku cloudflare

11
推荐指数
1
解决办法
2万
查看次数