Python-点击页面上所有带有selenium但具有不同代理的href?

时间:2017-01-13 13:33:26

标签: python selenium

正如标题所述,我如何使用chlenium python绑定与chromedriver(特别是),访问页面,然后单击href并重定向,但每次访问下一个href时都有不同的代理设置。我只需要示例代码。感谢。

1 个答案:

答案 0 :(得分:0)

从stack over flow本身检查这两个例子

示例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)

示例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()

https://stackoverflow.com/a/40113706/6626530

https://stackoverflow.com/a/40628176/6626530