As the title states, how can i use selenium python bindings with chromedriver(specifically), to visit a page, and click on an href and be redirected, but have different proxy settings each time a visit the next href. I just need sample code. Thanks.
Asked
Active
Viewed 153 times
-2
-
Maybe you can get all your links with beautifulsoup. Then open a new selenium webbrowser with a different proxy each time with those links – iFlo Jan 13 '17 at 13:39
-
I have done that and it works, but in this case doing that is not possible. I need to be redirected. – BrickleRex Jan 13 '17 at 13:57
-
1Welcome to Stack Overflow! Please read [ask]. Please provide the code you have tried and the execution result including any error messages, etc. Also provide a link to the page and/or the relevant HTML. – JeffC Jan 13 '17 at 14:10
1 Answers
0
Check these 2 examples from stack over flow itself
Example 1
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy, ProxyType
prox = Proxy()
prox.proxy_type = ProxyType.MANUAL
prox.http_proxy = "ip_addr:port"
prox.socks_proxy = "ip_addr:port"
prox.ssl_proxy = "ip_addr:port"
capabilities = webdriver.DesiredCapabilities.CHROME
prox.add_to_capabilities(capabilities)
driver = webdriver.Chrome(desired_capabilities=capabilities)
Example 2
from browsermobproxy import Server
server = Server("path/to/browsermob-proxy")
server.start()
proxy = server.create_proxy()
from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.set_proxy(proxy.selenium_proxy())
driver = webdriver.Firefox(firefox_profile=profile)
proxy.new_har("google")
driver.get("http://www.google.co.uk")
proxy.har # returns a HAR JSON blob
server.stop()
driver.quit()