def start():
for i in range(3):
make_request('https://www.google.com/search?q=работа', i)
user_agents = [
'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko)
Version/10.0 Mobile/14E304 Safari/602.1',
'Mozilla/5.0 (Linux; Android 6.0.1; Moto G (4)) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/87.0.4280.88 Mobile Safari/537.36',
'Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/87.0.4280.88 Mobile Safari/537.36',
]
proxies = [
'95.141.193.14:80',
'95.141.193.35:80',
'212.120.186.39:60963',
]
def make_request(url, index):
try:
user_agent = user_agents[index]
except IndexError:
user_agent = user_agents[0]
try:
proxy = proxies[index]
except IndexError:
proxy = proxies[0]
options = Options()
# меняем user-agent
options.add_argument(f'user-agent={user_agent}')
# игнор ошибок
options.add_argument('ignore-certificate-errors')
webdriver.DesiredCapabilities.CHROME['proxy'] = {
'httpProxy': proxy,
'ftpProxy': proxy,
'sslProxy': proxy,
'proxyType': 'MANUAL',
}
webdriver.DesiredCapabilities.CHROME['acceptSslCerts'] = True
driver = webdriver.Chrome(executable_path=PATH, chrome_options=options)
driver.get(url)
# закрываем браузер
driver.close()
driver.quit()
При первом запросе все работает, но при втором запросе, когда я меняю прокси, в консоль ide выпадает ошибка: selenium.common.exceptions.WebDriverException: Message: unknown error: net::ERR_TUNNEL_CONNECTION_FAILED
Кто-нибудь сталкивался с подобным?