Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can I manually set proxy settings in Python Selenium?
We can manually set proxy settings using Selenium webdriver in Python. It is done using the DesiredCapabilities class. We would create an object of this class and apply the add_to_capabilities method to it. Then pass the proxy capabilities as a parameter to this method.
Example
Code Implementation
from selenium import webdriver
from selenium.webdriver.common.proxy import ProxoxyType
#add proxy’s ip and port
p = '<proxy ip, port>'
pxy = Proxy()
#set proxy type
pxy.p_type = ProxyType.MANUAL
#http proxy
pxy.http_pxy = p
#ssl proxy
pxy.ssl_pxy = p
#object of DesiredCapabilities
c = webdriver.DesiredCapabilities.CHROME
#set proxy browser capabilties
pxy.add_to_capabilities(c)
#set chromedriver.exe path
driver = webdriver.Chrome(executable_path="C:\chromedriver.exe", desired_capabilities = c)
#launch URL
driver.get("https://www.tutorialspoint.com/index.htm")
#quit browser
driver.quit()Advertisements