DrissionPage
DrissionPage copied to clipboard
How do you proxy with auth:password. now its does not work
print("Starting initialize_browser...")
# Set the path to the browser executable
browser_path = r"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
# Create ChromiumOptions object
options = ChromiumOptions()
options.set_argument('--incognito')
options.set_argument('--no-sandbox')
# proxy_options = {
# 'proxy': {
# 'http': f'{self.proxy_string}',
# 'https': f'{self.proxy_string}'
# }
# }
# Set paths in ChromiumOptions
options.set_paths(browser_path=browser_path)
options.set_proxy(self.proxy_string)
# Create ChromiumPage with ChromiumOptions
self.driver = ChromiumPage(addr_driver_opts=options)
# Navigate to the specified URL
self.driver.get('https://ipleak.net')
I am facing the same problem
Hello Guys! I have the same problem....
是的,目前不支持带用户名密码的代理,你可以用插件实现这个功能。
https://github.com/Smartproxy/Selenium-proxy-authentication
This works perfectly fine for me, make sure to unzip the zip file created!
"Make sure to unzip the file created".
I changed the end of the code to the following so as to not create a zip:
directory_name = "your_directory"
if not os.path.exists(directory_name):
os.makedirs(directory_name)
manifest_path = os.path.join(directory_name, "manifest.json")
background_path = os.path.join(directory_name, "background.js")
with open(manifest_path, 'w') as manifest_file:
manifest_file.write(manifest_json)
with open(background_path, 'w') as background_file:
background_file.write(background_js)
Add this in your python code once the js and json file are created.
options=ChromiumOptions()
options.add_extension(directory_name)
I do not understand your problem, here is my full code.
import os
def proxies(username : str, password : str, endpoint : str, port : str):
manifest_json = """
{
"version": "1.0.0",
"manifest_version": 2,
"name": "Proxies",
"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']
);
""" % (endpoint, port, username, password)
directory_name = "your_directory"
if not os.path.exists(directory_name):
os.makedirs(directory_name)
manifest_path = os.path.join(directory_name, "manifest.json")
background_path = os.path.join(directory_name, "background.js")
with open(manifest_path, 'w') as manifest_file:
manifest_file.write(manifest_json)
with open(background_path, 'w') as background_file:
background_file.write(background_js)
Create the directory by calling
proxies(username, password, endpoint, port)
And then
options=ChromiumOptions()
options.add_extension(directory_name)
I do not understand your problem, here is my full code.
import os def proxies(username : str, password : str, endpoint : str, port : str): manifest_json = """ { "version": "1.0.0", "manifest_version": 2, "name": "Proxies", "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'] ); """ % (endpoint, port, username, password) directory_name = "your_directory" if not os.path.exists(directory_name): os.makedirs(directory_name) manifest_path = os.path.join(directory_name, "manifest.json") background_path = os.path.join(directory_name, "background.js") with open(manifest_path, 'w') as manifest_file: manifest_file.write(manifest_json) with open(background_path, 'w') as background_file: background_file.write(background_js)Create the directory by calling
proxies(username, password, endpoint, port)And then
options=ChromiumOptions() options.add_extension(directory_name)
hi How should I choose the default mode? Is it still the same as before?
https://github.com/Smartproxy/Selenium-proxy-authentication
This works perfectly fine for me, make sure to unzip the zip file created!
Hi, thank you! It's works good on Windows, but unfortunately on Linux server, with the same code, the same library, it does not using proxy at all... Maybe you know how to fix it?
Thanks in advance!
Its not working!
What version of Chrome are you using?
Its not working!
Did you fix your problem?
https://github.com/Smartproxy/Selenium-proxy-authentication This works perfectly fine for me, make sure to unzip the zip file created!
Hi, thank you! It's works good on Windows, but unfortunately on Linux server, with the same code, the same library, it does not using proxy at all... Maybe you know how to fix it?
Thanks in advance!
It doesn't work under Linux, have you solved this problem?