0

I'm working on python script using selenium to automate some tasks, the issue is that after some requests website block the account, after manual test i found changing proxy and user agent solve the issue, but i can't do it while the browser on the fly, i'm forced to close the browser each N times and re-open it with the new proxy and user-agent.

        options = Options()
        options.add_argument('log-level=3')
        proxy = '96.113.166.133:1080'
        options.add_argument('--proxy-server=socks5://' + proxy)
        ua = UserAgent()
        userAgent = ua.random
        options.add_argument(f'user-agent={userAgent}')


        driver = webdriver.Chrome(options=options)

        driver.get(url)

        with open("a.txt", "r") as ins:  # check each line in text
            try:

                for line in ins:

                    #Do some code

Now the question how can i change the proxy and user-agent after each N times without closing the browser like that ?

        options = Options()
        options.add_argument('log-level=3')


        driver = webdriver.Chrome(options=options)

        driver.get(url)

        with open("a.txt", "r") as ins:  # check each line in text
            try:

                for line in ins:
                    proxy = '96.113.166.133:1080'
                    options.add_argument('--proxy-server=socks5://' + proxy)
                    ua = UserAgent()
                    userAgent = ua.random
                    options.add_argument(f'user-agent={userAgent}')

                    #Do some code

Thanks

  • we set the chromeoptions while initiating the chrome driver instance and it cant be changed during runtime, unless you trigger a different instance. – Naveen Mar 14 '20 at 11:30
  • 1
    Does this answer your question? [Change ChromeOptions in an existing webdriver](https://stackoverflow.com/questions/53023853/change-chromeoptions-in-an-existing-webdriver) – Naveen Mar 14 '20 at 11:36

0 Answers0