Skip to content

Rotating proxies in UC MODE #2450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Nathan-Romano opened this issue Jan 25, 2024 · 1 comment
Closed

Rotating proxies in UC MODE #2450

Nathan-Romano opened this issue Jan 25, 2024 · 1 comment
Labels
question Someone is looking for answers UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode

Comments

@Nathan-Romano
Copy link

i wonder if its possible to rotate proxies and auth proxies using uc mode like so. i did research here but found nothing about it.
heres a code using selenium and seleniumwire:

def run_instance(proxy, count):
    while  count < num_instances:
        random_proxy = random.choice(proxy_list)
        try:
            response_proxy_up = requests.get('https://google.com', 
                                                    proxies={'https': f'http://user:pass@{random_proxy}' ,'http': 
                                                                            f'http://user:pass@{random_proxy}'},
                                                    timeout=8)
            response_proxy_up.raise_for_status()
            if response_proxy_up.status_code == 200:
                
                print("Proxy selecionada aleatoriamente:", random_proxy)
                options = {
                    'proxy': {
                        'http': f'http://user:pass@{random_proxy}',
                        'https': f'http://user:pass@{random_proxy}',
                    }
                }

                chrome_options = webdriver.ChromeOptions()
                chrome_options.add_argument("start-maximized")
                chrome_options.add_argument("--disable-blink-features=AutomationControlled")
                chrome_options.add_argument('--detach')
                #chrome_options.add_argument('--headless=new')
                chrome_options.add_experimental_option("detach", True)

                chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
                chrome_options.add_experimental_option("useAutomationExtension", False)
                driver = webdriver.Chrome(seleniumwire_options=options, options=chrome_options)
@mdmintz mdmintz added question Someone is looking for answers UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode labels Jan 25, 2024
@mdmintz
Copy link
Member

mdmintz commented Jan 25, 2024

There are options for that. (See #1832 (comment))

Example:

from parameterized import parameterized
from seleniumbase import BaseCase
BaseCase.main(__name__, __file__)

class SearchTests(BaseCase):
    @parameterized.expand(
        [
            ["user1:pass1@server1:port1"],
            ["user2:pass2@server2:port2"],
            ["user3:pass3@server3:port3"],
        ]
    )
    def test_parameterized_proxy(self, proxy_string):
        self.get_new_driver(proxy=proxy_string)
        # ...

And then run that like this:

pytest --uc -n=3 --multi-proxy

If you're not running multiple tests at the same time, it gets easier. Then you don't need the -n=NUM_THREADS or --multi-proxy options.

Additionally, you can call self.get_new_driver(uc=True, proxy=PROXY_STRING) to open a new UC Mode browser in the middle of a test with the proxy settings you specified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Someone is looking for answers UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode
Projects
None yet
Development

No branches or pull requests

2 participants