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()
CodePudding user response:
You need to map your proxy. And then iterate it.
CodePudding user response:
Try seleniumwire with uc: https://pypi.org/project/selenium-wire/#certificates:~:text=driver.wait_for_request() etc.-,Proxies,-If the site
Worked for me