分享页面
拖动logo到书签栏,立即收藏青果网络
控制台
|
登录/注册
子
用户在实名认证前无法开通业务
充值
未支付订单
未完成工单
未读消息
会员中心
退出登录
文档中心
产品介绍
使用指南
开发者指南
API接口
代码示例
常见问题
账户中心
查询
常见问题
产品相关
国内4种代理产品的区别
短效代理各提取方式的区别
可以免费试用吗?
常见产品问题
常见购买问题
退款说明
使用相关
“没有空闲通道”提取不到IP怎么办?
IP如何申请和释放
怎么查看已申请的IP
使用代理IP远程服务器返回错误码说明
怎么查看购买的通道IP量使用及剩余情况
如何测试socks5 和http 代理IP 的可用性
API调用频率跟IP的获取次数有关系吗?
如何使用带有用户名密码认证的HTTP(S)代理
代理IP操作中的常见问题汇总
产品相关
国内4种代理产品的区别
短效代理各提取方式的区别
可以免费试用吗?
常见产品问题
常见购买问题
退款说明
使用相关
“没有空闲通道”提取不到IP怎么办?
IP如何申请和释放
怎么查看已申请的IP
使用代理IP远程服务器返回错误码说明
怎么查看购买的通道IP量使用及剩余情况
如何测试socks5 和http 代理IP 的可用性
API调用频率跟IP的获取次数有关系吗?
如何使用带有用户名密码认证的HTTP(S)代理
代理IP操作中的常见问题汇总
常见问题
>
产品相关
>
Python自动化测试Selenium+chrome连接代理ip(账密模式)
Python自动化测试Selenium+chrome连接代理ip(账密模式)
发布时间:2022-09-16 14:16
此示例Python使用Selenium调用Chrome浏览器并通过代理进行自动化测试。 > 请注意:目前最高支持到Chrome 129.0.6614.3,后续版本暂不支持 - 代码示例 ```python import time import string import zipfile from selenium import webdriver from selenium.webdriver.chrome.service import Service targetURL = "http://myip.ipip.net" # 访问的目标站点 proxyHost = "61.171.76.145" # 代理IP地址 proxyPort = "50353" # 代理IP端口号 authKey = "x" # 代理IP的AuthKey password = "x" # 代理IP的AuthPwd def create_proxy_auth_extension(proxy_host, proxy_port, proxy_username, proxy_password, scheme='http', plugin_path=None): if plugin_path is None: plugin_path = r'./{}_{}_qgnet_proxyauth_plugin.zip'.format(proxy_username, proxy_password) manifest_json = """ { "version": "1.0.0", "manifest_version": 2, "name": "Chrome Proxy", "permissions": [ "proxy", "tabs", "unlimitedStorage", "storage", "
", "webRequest", "webRequestBlocking" ], "background": { "scripts": ["background.js"] }, "minimum_chrome_version":"22.0.0" } """ background_js = string.Template( """ var config = { mode: "fixed_servers", rules: { singleProxy: { scheme: "${scheme}", host: "${host}", port: parseInt(${port}) }, bypassList: ["localhost"] } }; chrome.proxy.settings.set({value: config, scope: "regular"}, function() {}); function callbackFn(details) { return { authCredentials: { username: "${username}", password: "${password}" } }; } chrome.webRequest.onAuthRequired.addListener( callbackFn, {urls: ["
"]}, ['blocking'] ); """ ).substitute( host=proxy_host, port=proxy_port, username=proxy_username, password=proxy_password, scheme=scheme, ) with zipfile.ZipFile(plugin_path, 'w') as zp: zp.writestr("manifest.json", manifest_json) zp.writestr("background.js", background_js) return plugin_path if __name__ == '__main__': # 此处指定您的webdriver路径,版本需要跟您所使用的Chrome版本一致, # 下载地址https://registry.npmmirror.com/binary.html?path=chromedriver/ driver_location = "./chromedriver/chromedriver_v106_win.exe" proxy_auth_plugin_path = create_proxy_auth_extension( proxy_host=proxyHost, proxy_port=proxyPort, proxy_username=authKey, proxy_password=password) option = webdriver.ChromeOptions() option.add_argument("--start-maximized") # 窗口最大化运行 option.add_extension(proxy_auth_plugin_path) # 添加proxy插件 # 此处selenium版本为4.8.0 driver = webdriver.Chrome(service=Service(driver_location), options=option) driver.get(targetURL) time.sleep(100) driver.quit() ``` - 运行结果 [](https://cos.qg.net/uploads/image/20220916/d1a8b394a7d64cdd99b120803390ac56.png)
上一篇:没有了
下一篇:没有了
相关文章
代理IP操作中的常见问题汇总
如何使用带有用户名密码认证的HTTP(S)代理
长效代理-使用指南-手动版
如何测试socks5 和http 代理IP 的可用性
Postman如何使用代理
国内区域编码
本文导读