I want to be able to run through a file and take each proxy by line and use it in each window as that windows own personal proxy. Running this code i get the error "invalid argument: specifying 'socksProxy' requires an integer for 'socksVersion'. I think it can successful add the proxy because i have a try and exception and it goes though it and prints that it successfully added the proxy. Im not sure where it is getting caught. This is my first shot at web requests and automation with python/selenium so any help would be greatly appreciated...
import selenium.webdriver as webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.proxy import Proxy, ProxyType
from fake_useragent import UserAgent
import time
import random
chrome_path = r"C:\Users\Michael\PycharmProjects\FlashCop\chromedriver.exe"
times = ""
start_page = ""
options = Options()
proxy = Proxy()
new_proxy = []
pro_sheet = open("proxies.txt", "r")
for line in pro_sheet:
new_proxy.append(line)
print(str(new_proxy))
def start_pages(target_page):
j = 0
for x in range(0, len(page_number)):
j = j + 1
time.sleep(3)
ua = UserAgent()
user_agent = ua.random
print("Successfully added fake user...")
time.sleep(1)
options.add_argument(f'user-agent={user_agent}')
options.add_experimental_option("detach", True)
options.add_argument("window-size=600,600")
options.add_argument('--disable-extensions')
options.add_argument('--profile-directory=Default')
options.add_argument("--incognito")
options.add_argument("--disable-plugins-discovery")
options.add_argument("--proxy-server=%s" % random.choice(new_proxy))
options.add_argument("ignore-certificate-errors")
# chrome_options.add_argument("--headless")
# print('initiated headless mode')
options.add_experimental_option("detach", True)
print("Successfully Detached chrome...")
time.sleep(1)
print("Attempting to add proxy...")
try:
proxy.proxy_type = ProxyType.MANUAL
proxy.autodetect = False
proxy.http_proxy = proxy.ssl_proxy = proxy.socks_proxy = random.choice(new_proxy)
options.proxy = proxy
except Exception as e:
print(e)
options.add_argument("ignore-certificate-errors")
print("Completed adding arguments to browser...")
time.sleep(1)
print("Browser " + str(j) + " is using proxy: " + str(new_proxy))
time.sleep(1)
capabilities = webdriver.DesiredCapabilities.CHROME
proxy.add_to_capabilities(capabilities)
driver = webdriver.Chrome(chrome_path, options=options, desired_capabilities=capabilities)
print("added options")
time.sleep(1)
driver.delete_all_cookies()
print("deleted old cookies...")
time.sleep(1)
driver.set_window_position(0, 0)
driver.get(target_page)
print("Browser number " + str(j) + " has opened successfully...")
while times == "":
times = input("How many pages do you want?\n")
# url = input("Yeezy Supply or Adidas?""\nEither 'YS' or 'Adidas'\n")
# url_choice = url.lower()
page_number = list()
for i in range(0, int(times)):
page_number.append(times)
# if url_choice == 'ys':
# start_page = 'https://yeezysupply.com/'
# start_pages(start_page)
# elif url_choice == 'adidas':
# start_page = 'https://www.adidas.com/yeezy'
# start_pages(start_page)
start_page = 'https://www.adidas.com/yeezy'
start_pages(start_page)
Note: The proxy that i am trying to use is a replica of this one
x3PPAU9.nyc.myproxies.com:99099:mkevin2398:o3VXtvjHkWr9
where mkevin
is the username and o3VXtvjHkWr9
is the password.
NOTE: This proxy will not work for your test as i changed login.