Running selenium behind a proxy server

前端 未结 4 1716
一生所求
一生所求 2020-12-13 15:38

I have been using selenium for automatic browser simulations and web scraping in python and it has worked well for me. But now, I have to run it behind a proxy server. So no

4条回答
  •  一向
    一向 (楼主)
    2020-12-13 16:37

    The official Selenium documentation (http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp#using-a-proxy) provides clear and helpful guidelines about using a proxy. For Firefox (which is the browser of choice in your sample code) you should do the following:

    from selenium import webdriver
    from selenium.webdriver.common.proxy import *
    
    myProxy = "host:8080"
    
    proxy = Proxy({
        'proxyType': ProxyType.MANUAL,
        'httpProxy': myProxy,
        'ftpProxy': myProxy,
        'sslProxy': myProxy,
        'noProxy': '' # set this value as desired
        })
    
    driver = webdriver.Firefox(proxy=proxy)
    

提交回复
热议问题