Open zaivanza opened 2 years ago
have you tried Selenium Chrome Proxy Authentication ?
In our project we use UC through seleniumwire library which provide proxy auth: https://pypi.org/project/selenium-wire/
import seleniumwire.undetected_chromedriver as webdriver
seleniumwire_options = {
'proxy': {
'http': 'http://' + IP, # user:pass@ip:port
'https': 'http://' + IP,
'no_proxy': 'localhost,127.0.0.1'
}
driver = webdriver.Chrome(options = options, seleniumwire_options = seleniumwire_options, version_main = my_version)
In our project we use UC through seleniumwire library which provide proxy auth: https://pypi.org/project/selenium-wire/
import seleniumwire.undetected_chromedriver as webdriver seleniumwire_options = { 'proxy': { 'http': 'http://' + IP, # user:pass@ip:port 'https': 'http://' + IP, 'no_proxy': 'localhost,127.0.0.1' } driver = webdriver.Chrome(options = options, seleniumwire_options = seleniumwire_options, version_main = my_version)
thanks
@JulesSoulfly that's a very handy solution. But some site might detect you with TLS fingerprinting. The solution is to create and add an extension on the fly.
В нашем проекте мы используем UC через библиотеку seleniumwire, которая обеспечивает прокси-аутентификацию: https://pypi.org/project/selenium-wire/
import seleniumwire.undetected_chromedriver as webdriver seleniumwire_options = { 'proxy': { 'http': 'http://' + IP, # user:pass@ip:port 'https': 'http://' + IP, 'no_proxy': 'localhost,127.0.0.1' } driver = webdriver.Chrome(options = options, seleniumwire_options = seleniumwire_options, version_main = my_version) `` In our project we use UC through seleniumwire library which provide proxy auth: https://pypi.org/project/selenium-wire/
import seleniumwire.undetected_chromedriver as webdriver seleniumwire_options = {
'proxy': { 'http': 'http://' + IP, # user:pass@ip:port 'https': 'http://' + IP, 'no_proxy': 'localhost,127.0.0.1' } driver = webdriver.Chrome(options = options, seleniumwire_options = seleniumwire_options, version_main = my_version)
help me please
import seleniumwire.undetected_chromedriver as webdriver
seleniumwire_options = {
'proxy': {
'http': 'http://' + IP, # user:pass@ip:port
'https': 'http://' + IP,
'no_proxy': 'localhost,127.0.0.1'
}
print(0.1)
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(options = options, seleniumwire_options = seleniumwire_options)
print(1)
driver.get('https://www.google.com/')
print(2)
(no errors)
@sebdelsol I have used the following code to fetch verification code from email account but I am getting detected
import pandas as pd
import re
# No Headless, Proxy, undetected
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
import undetected_chromedriver as uc
import seleniumwire.undetected_chromedriver as uc
DRIVER_OPTIONS = uc.ChromeOptions()
DRIVER_OPTIONS.add_argument('--disable-extensions')
DRIVER_OPTIONS.add_argument("--disable-plugins-discovery")
DRIVER_OPTIONS.add_argument("--start-maximized")
DRIVER_OPTIONS.add_argument("--log-level=3")
DRIVER_OPTIONS.add_argument('--headless')
DRIVER_OPTIONS.add_argument('--ignore-certificate-errors-spki-list')
DRIVER_OPTIONS.add_argument('--ignore-ssl-errors')
DRIVER_OPTIONS.add_argument('--no-sandbox')
DRIVER_OPTIONS.add_argument('--disable-dev-shm-usage')
DRIVER_OPTIONS.add_argument("--window-size=1325x744")
host_ip = "XX.XXX.XX.XX"
port = "XXXXX"
proxy_username = "proxy_username"
proxy_password = "proxy_password"
ipCheckUrl = "https://www.whatismyip.com/"
ipCheckUrl1 = "http://whatismyipaddress.com"
accounts = pd.read_csv('data.csv')
def get_verification_code_yahoo(driver):
time.sleep(3)
driver.get(ipCheckUrl)
time.sleep(3)
driver.save_screenshot("yahoo_reached_what_is_my_ip_address.png")
url = 'https://login.yahoo.com/'
driver.get(url)
time.sleep(3)
# Code for fetching verification_code
driver.quit()
return verificationCode
if __name__ == '__main__':
for index, profile_info in accounts.iterrows():
username = profile_info['email']
password = profile_info['password']
gmail_password = profile_info['password']
verification_email = profile_info['recovery_email']
host = profile_info['host']
options = {
'proxy': {
'http': 'http://Username:Password@xx.xxx.xx.x:xxxx',
'https': 'https://Username:Password@xx.xxx.xx.x:xxxx',
'no_proxy': 'localhost,127.0.0.1'
}
}
seleniumwire_options = {'proxy': {'http': 'http://Username:Password@xx.xxx.xx.x:xxxx',
'https': 'http://Username:Password@xx.xxx.xx.x:xxxx'},
'disable_encoding': True, 'verify_ssl': False,
'ignore_http_methods': ['GET', 'POST', 'OPTIONS']}
driver = uc.Chrome(options=DRIVER_OPTIONS, seleniumwire_options=seleniumwire_options)
verification_code = get_verification_code_yahoo(driver,)
Can anyone please help me so that I can solve this problem. I have been stuck on this for a week now and cannot seem to find a solution for this.
you should try without headless
@sebdelsol I have been successful without headless The problem is that I want to run this on a Ubuntu server
In our project we use UC through seleniumwire library which provide proxy auth: https://pypi.org/project/selenium-wire/
import seleniumwire.undetected_chromedriver as webdriver seleniumwire_options = { 'proxy': { 'http': 'http://' + IP, # user:pass@ip:port 'https': 'http://' + IP, 'no_proxy': 'localhost,127.0.0.1' } driver = webdriver.Chrome(options = options, seleniumwire_options = seleniumwire_options, version_main = my_version)
Got this error when run that code - NameError: name 'options' is not defined
have you solve this problem?got the same problem。
Selenium-wire is archived by the author: https://github.com/wkeeling/selenium-wire
Any alternative?
Please tell me how do I use a proxy?
Here is my code: proxy = {'proxy': {'https': f'http://{login}:{password}@{address}:3000'}} driver = uc.Chrome(enable_cdp_events=True)
def print_func(eventdata): print(eventdata)
driver.add_cdp_listener("Network.dataReceived", print_func) driver.add_cdp_listener(f'--proxy-server={proxy}', print_func) # doesn't work driver.get(url)
driver.add_cdp_listener('Network.requestWillBeSent', print_func) driver.add_cdp_listener('Network.dataReceived', print_func) driver.add_cdp_listener(f'--proxy-server={proxy}', print_func) # doesn't work
driver.get(url)