如何使用Python在Selenium中使用用户名和密码对代理进行身份验证

H Athukorala

我正在尝试使用Python在Selenium中使用用户名和密码对代理进行身份验证,但是当前代码无法正常工作。我尝试了许多解决方案,但没有一个起作用。

代理示例,

IP = xxx.xx.xx.xx
PORT = xxxxx
USERNAME = USERNAME
PASSWORD = PASSWORD

我使用了以下代码,

driver.execute_script("""
          Services.prefs.setIntPref('network.proxy.type', 1);
          Services.prefs.setCharPref("network.proxy.http", arguments[0]);
          Services.prefs.setIntPref("network.proxy.http_port", arguments[1]);
          Services.prefs.setCharPref("network.proxy.ssl", arguments[0]);
          Services.prefs.setIntPref("network.proxy.ssl_port", arguments[1]);
          Services.prefs.setCharPref('network.proxy.socks', arguments[4]);
          Services.prefs.setIntPref('network.proxy.socks_port', arguments[5]);
          Services.prefs.setCharPref('network.proxy.socks_username', arguments[6]);
          Services.prefs.setCharPref('network.proxy.socks_password', arguments[7]);
          """, http_addr, http_port, ssl_addr, ssl_port, socks_addr, socks_port, socks_username, socks_password)

我也尝试了其他一些代码片段。试图将值也放入警报框。那么有人可以帮助我解决这个问题吗?提前致谢。

哈西塔·贾亚瓦达那

您可以使用AutoIt来实现并且它具有Python绑定PyAutoIt使用PIP-安装PyAutoIt之后pip install PyAutoIt,以下代码将完成您的工作。

import autoit

autoit.win_wait_active("Authentication Required") # title of the dialog box to wait. so it will wait for the Authentication Required dialog
autoit.send("username", 1) # second parameter is the mode (changes how "keys" is processed)
autoit.send("{TAB}") # press tab key to go to the password field
autoit.send("password", 1)
autoit.send("{Enter}") # press enter key

有关send方法中第二个参数的更多信息,下面是代码,

def send(send_text, mode=0):
    """
    Sends simulated keystrokes to the active window.
    :param send_text:
    :param mode: Changes how "keys" is processed:
        flag = 0 (default), Text contains special characters like + and ! to
         indicate SHIFT and ALT key presses.
        flag = 1, keys are sent raw.
    :return:
    """
    AUTO_IT.AU3_Send(LPCWSTR(send_text), INT(mode))

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用Java代码设置基本身份验证(用户名和密码)

在Android中仅使用用户名和密码通过Firestore进行身份验证

在特定路径中使用用户名/密码身份验证

我如何使用Spring Security通过ID和密码而不是用户名和密码对用户进行身份验证

使用节点js,AngularJs和JWT使用用户名和密码进行身份验证

使用用户名使用UnboundID对Active Directory用户进行身份验证

使用用户名而不是电子邮件进行JWTAuth身份验证

如何使用用户名和密码向Azure REST API进行身份验证(无应用程序ID)

如何使用用户名和密码对Kubernetes kubectl进行身份验证?

laravel中仅使用用户名(id)进行身份验证

azure-devops-node-api:使用用户名和密码进行身份验证

如何在python中使用ADAL使用Azure区块链工作台的用户名和密码获取身份验证承载?

如何使用Python / Selenium设置代理身份验证用户名:密码

仅使用用户名进行身份验证

使用用户名和密码进行密钥验证

如何针对盐和散列的密码和用户名对用户进行身份验证?

是否可以仅使用Marketo使用用户名和密码进行OAuth2身份验证?

如何仅使用一个字段进行网页身份验证(而不是用户名和密码)

使用用户名而不是电子邮件进行身份验证laravel 5.2

使用用户名或电子邮件进行身份验证

在Angular中使用http $进行基本身份验证-传递用户名/密码和grant_type

使用用户名和密码获取谷歌身份验证令牌

Azure AD B2C:是否可以以自定义形式使用用户名和密码进行身份验证

如何使用经过身份验证的用户名和密码离线下载网站?

如何在控制台中创建登录名,在其中使用存储在文件 c# 中的用户名和密码进行身份验证

Laravel - 无法使用用户名在 SMTP 服务器上进行身份验证

使用用户名和密码自定义 Firebase 身份验证

K8S 上的 Keyclaok:无法使用用户名和密码对用户进行身份验证

Paramiko SFTP 不会使用正确的用户名和密码进行身份验证