wkeeling / selenium-wire

Extends Selenium's Python bindings to give you the ability to inspect requests made by the browser.
MIT License
1.86k stars 241 forks source link

How can I change proxies in same session & site? #668

Open seadhy opened 1 year ago

seadhy commented 1 year ago

Hello. I want the proxy used to change every time I go to a site with the driver.get() function and then refresh the site using the driver.execute_script("location.reload();") function. I tried this in the form of the code I gave below, but there is no change.

import time
import seleniumwire.undetected_chromedriver as uc

if __name__ == '__main__':
    driver = uc.Chrome()

    driver.get('https://ipv4.icanhazip.com')

    proxies = [
        'username:password@hostname:port',
        'username:password@hostname:port'
    ]

    for proxy in proxies:
        driver.proxy = {
                'http': 'http://' + proxy,
                'https': 'https://' + proxy
            }

        driver.execute_script("location.reload();")

        time.sleep(3)

Is this possible with the seleniumwire module? Waiting for your help @wkeeling