【问题标题】:selenium get blocked quickly by websites - SSL handshake errorselenium 被网站迅速阻止 - SSL 握手错误
【发布时间】:2022-11-03 09:32:31
【问题描述】:

我在我的项目中使用硒和硒线。 我正在编写流程以登录到 aws 和 gcp 门户。 我的流程运行良好,但是当我进入 aws/gcp 门户时出现错误,我看到空白页..

aws 门户 链接:https://us-east-1.console.aws.amazon.com/console/home?region=us-east-1#

gcp 门户

硒驱动程序 `

from seleniumwire import webdriver
from seleniumwire.webdriver import ChromeOptions

def test_aws_flow():

    options = ChromeOptions()
    options.add_experimental_option("detach", True)
    options.add_argument('--no-sandbox')
    options.add_argument('--single-process')
    options.add_argument('--disable-dev-shm-usage')
    options.add_argument("--start-maximized")
    options.add_argument('--auto-open-devtools-for-tabs')
    options.add_argument('--log-level=2')
    options.add_argument('--disable-features=IsolateOrigins,site-per-process')
    options.add_argument("--ignore_ssl")
    options.add_argument('--ignore-ssl-errors')
    options.add_argument('--ignore-certificate-errors')
    options.add_argument("--disable-extensions")
    options.add_argument("--disable-setuid-sandbox")
    options.add_argument("--dns-prefetch-disable")
    options.add_argument('ignore-certificate-errors')
    options.add_argument('disable-web-security')
    options.add_argument('--allow-insecure-localhost')

    driver = webdriver.Chrome(options=options)
    driver.get('....any-hidden-url')
    # more flow actions - then it open aws portal
    


`

我在 github 中发现了一些对我不起作用的库 selenium 线的问题。 https://github.com/wkeeling/selenium-wire/issues/566

  • 他们建议与未检测到的 bot chromedriver 一起使用,我尝试过,但仍然显示相同的问题。

一些更新

我添加了 openssl.cnf 并在我的测试中使用 pycharm 在本地运行它

openssl_conf = openssl_init

[openssl_init]
ssl_conf = ssl_sect

[ssl_sect]
system_default = system_default_sect

[system_default_sect]
Options = UnsafeLegacyRenegotiation

它成功登录到 gcp 和 aws ..为什么会这样?当我将它部署到 aws lambda 时,如何确保它不会在 prod 环境中发生?

【问题讨论】:

    标签: selenium selenium-webdriver selenium-chromedriver ui-automation e2e-testing


    【解决方案1】:

    如果您的页面打不开,请告诉我。我相信他们是 检测机器人。您可能想尝试使用假用户代理,如 下面的代码。

    from selenium import webdriver
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver import ActionChains
    from selenium.webdriver.chrome.options import Options
    import time
    
    options = Options()
    user_agent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.517 Safari/537.36'
    options.add_argument('user-agent={0}'.format(user_agent))
    
    driver = webdriver.Chrome(options=options)
    wait = WebDriverWait(driver, 20)
    action = ActionChains(driver)
    
    driver.get("https://us-east-1.console.aws.amazon.com/console/home?region=us-east-1#")
    time.sleep(20)
    driver.quit() 
    

    注意 - 请删除您不需要的额外代码。谢谢..!

    【讨论】:

    • 它没有用..我编辑了我的帖子,如果你能看到一些更新
    猜你喜欢
    • 2017-01-20
    • 1970-01-01
    • 2017-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-18
    • 2015-02-03
    • 2016-08-08
    相关资源
    最近更新 更多