P
P
potapovdmtriy2021-05-17 11:55:23
Python
potapovdmtriy, 2021-05-17 11:55:23

How to make Selenium work with all types of proxies?

browser_options = Options()
browser_options.add_argument('--proxy-server=socks4://%s' % proxy)


In the way described above, I can only connect to socks4?
How to force to use all types?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Segey K., 2021-05-17
@potapovdmtriy

For proxy use seleniumwire

from seleniumwire import webdriver
from fake_useragent import UserAgent
from selenium.webdriver import FirefoxProfile

seleniumwire_options = {
        'proxy': {
            'http': f'http://'
                    f'{proxy_data["username"]}:{proxy_data["password"]}@'
                    f'{proxy_data["proxy_address"]}:{proxy_data["ports"]["socks5"]}',
            'https': f'https://'
                     f'{proxy_data["username"]}:{proxy_data["password"]}@'
                     f'{proxy_data["proxy_address"]}:{proxy_data["ports"]["socks5"]}',
            'no_proxy': 'localhost,127.0.0.1,dev_server:8080'
        }
    }

profile = FirefoxProfile()
user_agent = UserAgent().random
profile.set_preference("general.useragent.override", user_agent)

options = Options()
options.add_argument('--headless')

driver = webdriver.Firefox(
        firefox_profile=profile,
        options=options,
        seleniumwire_options=seleniumwire_options
    )
driver.get('http://<your_url>')

S
SKEPTIC, 2021-05-17
@pro100chel

Depending on the type of proxy, change socks4 to the desired type.
What's the problem then?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question