如何使用udtected_chromium启用使用用户名和密码的代理?
我正在使用undetected_chromedriver,但我无法让代理人工作,我不知道我的代码运行平稳,但仍然不启用代理。 我有使用用户名和密码的代理人,但我无法正常工作 我的Chrome会话开始,但它显示当前的IP不会更改
我的代码:
import undetected_chromedriver.v2 as uc
import os
import zipfile
import time
host = '91.201.40.130'
port = 12115
username = 'alos081100RnC5'
password = 'YRhSahmNYX'
manifest_json = """
{
"version": "1.0.0",
"manifest_version": 2,
"name": "Chrome Proxy",
"permissions": [
"proxy",
"tabs",
"unlimitedStorage",
"storage",
"<all_urls>",
"webRequest",
"webRequestBlocking"
],
"background": {
"scripts": ["background.js"]
},
"minimum_chrome_version":"22.0.0"
}
"""
background_js = """
var config = {
mode: "fixed_servers",
rules: {
singleProxy: {
scheme: "http",
host: "%s",
port: parseInt(%s)
},
bypassList: ["localhost"]
}
};
chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});
function callbackFn(details) {
return {
authCredentials: {
username: "%s",
password: "%s"
}
};
}
chrome.webRequest.onAuthRequired.addListener(
callbackFn,
{urls: ["<all_urls>"]},
['blocking']
);
""" % (host, port , username, password)
def get_chromedriver(use_proxy=False, user_agent=None):
path = os.path.dirname(os.path.abspath(__file__))
chrome_options = uc.ChromeOptions()
if use_proxy:
pluginfile = 'proxy_auth_plugin.zip'
with zipfile.ZipFile(pluginfile, 'w') as zp:
zp.writestr("manifest.json", manifest_json)
zp.writestr("background.js", background_js)
chrome_options.add_extension(pluginfile)
if user_agent:
chrome_options.add_argument('--user-agent=%s' % user_agent)
driver = uc.Chrome(options=chrome_options)
return driver
def main():
driver = get_chromedriver(use_proxy=True)
driver.get("https://whatismyipaddress.com")
if __name__ == '__main__':
main()
I am using undetected_chromedriver but i can't get the proxy to work i don't know what's the issue as my code runs smooth but still don't enables the proxy.
I have working proxy with username and password but i can't make it work
My chrome session starts but it shows the current Ip does not changes it
My Code:
import undetected_chromedriver.v2 as uc
import os
import zipfile
import time
host = '91.201.40.130'
port = 12115
username = 'alos081100RnC5'
password = 'YRhSahmNYX'
manifest_json = """
{
"version": "1.0.0",
"manifest_version": 2,
"name": "Chrome Proxy",
"permissions": [
"proxy",
"tabs",
"unlimitedStorage",
"storage",
"<all_urls>",
"webRequest",
"webRequestBlocking"
],
"background": {
"scripts": ["background.js"]
},
"minimum_chrome_version":"22.0.0"
}
"""
background_js = """
var config = {
mode: "fixed_servers",
rules: {
singleProxy: {
scheme: "http",
host: "%s",
port: parseInt(%s)
},
bypassList: ["localhost"]
}
};
chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});
function callbackFn(details) {
return {
authCredentials: {
username: "%s",
password: "%s"
}
};
}
chrome.webRequest.onAuthRequired.addListener(
callbackFn,
{urls: ["<all_urls>"]},
['blocking']
);
""" % (host, port , username, password)
def get_chromedriver(use_proxy=False, user_agent=None):
path = os.path.dirname(os.path.abspath(__file__))
chrome_options = uc.ChromeOptions()
if use_proxy:
pluginfile = 'proxy_auth_plugin.zip'
with zipfile.ZipFile(pluginfile, 'w') as zp:
zp.writestr("manifest.json", manifest_json)
zp.writestr("background.js", background_js)
chrome_options.add_extension(pluginfile)
if user_agent:
chrome_options.add_argument('--user-agent=%s' % user_agent)
driver = uc.Chrome(options=chrome_options)
return driver
def main():
driver = get_chromedriver(use_proxy=True)
driver.get("https://whatismyipaddress.com")
if __name__ == '__main__':
main()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要映射代理。然后迭代它。
You need to map your proxy. And then iterate it.
尝试使用UC: https://pypi.org/project/selenium-wire/#certificates:~: text = driver.wait_for_request()%20ETC .-,PROXIES,PROXIES,-IF%20 the%20 site
为我工作
Try seleniumwire with uc: https://pypi.org/project/selenium-wire/#certificates:~:text=driver.wait_for_request()%20etc.-,Proxies,-If%20the%20site
Worked for me