title: Add proxy to selenium python script
body: <p>I'm really new to python and
  I have a python selenium script</p>
  <pre><code>    #Developed by github.com/useragents
  #This script was made for educational purposes. I am not responsible for your actions using this script. This code is a few months old, hence why it may not appear as professional but still works to this day.
  try:
      from selenium import webdriver
      import time, os, ctypes, requests
      from colorama import Fore, init
      import warnings, selenium, platform
  except ImportError:
      input(&quot;Error while importing modules. Please install the modules in requirements.txt&quot;)
  
  init(convert = True, autoreset = True)
  warnings.filterwarnings(&quot;ignore&quot;, category=DeprecationWarning)
  
  clear = &quot;clear&quot;
  if platform.system() == &quot;Windows&quot;:
      clear = &quot;cls&quot;
  
  os.system(clear)
  
  ascii_text = f&quot;&quot;&quot;{Fore.RED}
                  ████████▀▀▀████
                  ████████────▀██
                  ████████──█▄──█
                  ███▀▀▀██──█████
                  █▀──▄▄██──█████
                  █──█████──█████
                  █▄──▀▀▀──▄█████
                  ███▄▄▄▄▄███████ github.com/useragents
  &quot;&quot;&quot;
  
  class automator:
      
      def __init__(self):
          options = webdriver.ChromeOptions()
          options.add_argument('--ignore-certificate-errors')
          options.add_experimental_option(&quot;excludeSwitches&quot;, [&quot;enable-logging&quot;])
          self.xpaths = {
              &quot;followers&quot;: &quot;/html/body/div[4]/div[1]/div[3]/div/div[1]/div/button&quot;,
              &quot;likes&quot;: &quot;/html/body/div[4]/div[1]/div[3]/div/div[2]/div/button&quot;,
              &quot;views&quot;: &quot;/html/body/div[4]/div[1]/div[3]/div/div[4]/div/button&quot;,
              &quot;shares&quot;: &quot;/html/body/div[4]/div[1]/div[3]/div/div[5]/div/button&quot;
          }
          try:
              self.driver = webdriver.Chrome(options = options)
          except Exception as e:
              self.error(f&quot;Error trying to load web driver: {e}&quot;)
          self.status = {}
          self.sent = 0
          self.cooldowns = 0
          self.ratelimits = 0
  
      def check_status(self):
          for xpath in self.xpaths:
              value = self.xpaths[xpath]
              element = self.driver.find_element_by_xpath(value)
              if not element.is_enabled():
                  self.status.update({xpath: &quot;[OFFLINE]&quot;})
              else:
                  self.status.update({xpath: &quot;&quot;})
      
      def check_for_captcha(self):
          while True:
              try:
                  if &quot;Enter the word&quot; not in self.driver.page_source:
                      return
              except:
                  return
              os.system(clear)
              print(ascii_text)
              print(f&quot;{self.console_msg('Error')} Complete the CAPTCHA in the driver.&quot;)
              time.sleep(1)
  
      def console_msg(self, status):
          colour = Fore.RED
          if status == &quot;Success&quot;:
              colour = Fore.GREEN
          return f&quot;                {Fore.WHITE}[{colour}{status}{Fore.WHITE}]&quot;
      
      def update_ascii(self):
          options = f&quot;&quot;&quot;
  {self.console_msg(&quot;1&quot;)} Follower Bot {Fore.RED}{self.status[&quot;followers&quot;]}
  {self.console_msg(&quot;2&quot;)} Like Video Bot {Fore.RED}{self.status[&quot;likes&quot;]}
  {self.console_msg(&quot;3&quot;)} View Bot {Fore.RED}{self.status[&quot;views&quot;]}
  {self.console_msg(&quot;4&quot;)} Share Bot {Fore.RED}{self.status[&quot;shares&quot;]}
          &quot;&quot;&quot;
          return ascii_text + options
      
      def check_url(self, url):
          redirect = True
          if &quot;vm.tiktok.com/&quot; in url:
              redirect = False
          if redirect:
              if &quot;/video/&quot; not in url:
                  return False
          session = requests.Session()
          r = session.get(url, allow_redirects=redirect)
          if redirect:
              if r.status_code == 200:
                  return True
              return False
          location = r.headers[&quot;Location&quot;]
          if &quot;/video&quot; in location:
              return True
          return False
  
      def convert(self, min, sec):
          seconds = 0
          if min != 0:
              answer = int(min) * 60
              seconds += answer
          seconds += int(sec) + 15
          return seconds
  
      def check_submit(self, div):
          remaining = f&quot;/html/body/div[4]/div[{div}]/div/div/h4&quot;
          try:
              element = self.driver.find_element_by_xpath(remaining)
          except:
              return None, None
          if &quot;READY&quot; in element.text:
              return True, True
          if &quot;seconds for your next submit&quot; in element.text:
              output = element.text.split(&quot;Please wait &quot;)[1].split(&quot; for&quot;)[0]
              minutes = element.text.split(&quot;Please wait &quot;)[1].split(&quot; &quot;)[0]
              seconds = element.text.split(&quot;(s) &quot;)[1].split(&quot; &quot;)[0]
              sleep_duration = self.convert(minutes, seconds)
              return sleep_duration, output
          return element.text, None
      
      def update_cooldown(self, sleep_time, bot, rl = False):
          cooldown = sleep_time
          while True:
              time.sleep(1)
              try:
                  cooldown -= 1
              except TypeError:
                  break
              self.update_title(bot, cooldown, rl)
              if cooldown == 0:
                  break
      
      def wait_for_ratelimit(self, arg, div):
          time.sleep(1)
          duration, output = self.check_submit(div)
          if duration == True:
              return
          if output == None:
              time.sleep(0.7)
              self.wait_for_ratelimit(arg, div)
          self.cooldowns += 1
          self.update_cooldown(duration, arg)
  
      def send_bot(self, video_url, bot, div):
          try:
              self.driver.find_element_by_xpath(self.xpaths[bot]).click()
              time.sleep(0.5)
          except:
              pass
          enter_link_xpath = f&quot;/html/body/div[4]/div[{div}]/div/form/div/input&quot; 
          link = self.driver.find_element_by_xpath(enter_link_xpath)
          link.clear()
          link.send_keys(video_url)
          self.driver.find_element_by_xpath(f&quot;/html/body/div[4]/div[{div}]/div/form/div/div/button&quot;).click() #Search button
          time.sleep(0.8)
          send_button_xpath = f&quot;/html/body/div[4]/div[{div}]/div/div/div[1]/div/form/button&quot;
          try:
              self.driver.find_element_by_xpath(send_button_xpath).click() 
          except selenium.common.exceptions.NoSuchElementException:
              self.wait_for_ratelimit(bot, div)
              self.driver.find_element_by_xpath(f&quot;/html/body/div[4]/div[{div}]/div/form/div/div/button&quot;).click() #Search button
              time.sleep(0.8)
              self.driver.find_element_by_xpath(send_button_xpath).click()
          time.sleep(3)
          try:
              s = self.driver.find_element_by_xpath(f&quot;/html/body/div[4]/div[{div}]/div/div/span&quot;)
              if &quot;Too many requests&quot; in s.text:
                  self.ratelimits += 1
                  self.update_cooldown(50, bot, True)
                  self.send_bot(video_url, bot, div)
              elif &quot;sent&quot; in s.text:
                  sent = 100
                  if bot == &quot;likes&quot;:
                      try:
                          sent = int(s.text.split(&quot; Hearts&quot;)[0])
                      except IndexError:
                          sent = 30
                  if bot == &quot;views&quot;:
                      sent = 2500
                  if bot == &quot;shares&quot;:
                      sent = 500
                  self.sent += sent
              else:
                  print(s.text)
          except:
              self.sent += sent
          self.update_title(bot, &quot;0&quot;)
          self.wait_for_ratelimit(bot, div)
          self.send_bot(video_url, bot, div)
  
      def update_title(self, bot, remaining, rl = False):
          if clear == &quot;cls&quot;:
              os.system(clear)
              ctypes.windll.kernel32.SetConsoleTitleW(f&quot;TikTok AIO | Sent: {self.sent} | Cooldown: {remaining}s | Developed by @useragents on Github&quot;)
              print(ascii_text)
              print(self.console_msg(self.sent) + f&quot; Sent {bot}&quot;)
              rl_cooldown = &quot;0&quot;
              cooldown = &quot;0&quot;
              if rl:
                  rl_cooldown = remaining
              else:
                  cooldown = remaining
              print(self.console_msg(self.cooldowns) + f&quot; Cooldowns {Fore.WHITE}[{Fore.RED}{cooldown}s{Fore.WHITE}]&quot;)
              print(self.console_msg(self.ratelimits) + f&quot; Ratelimits {Fore.WHITE}[{Fore.RED}{rl_cooldown}s{Fore.WHITE}]&quot;)
  
      def main(self):
          if clear == &quot;cls&quot;:
              ctypes.windll.kernel32.SetConsoleTitleW(&quot;TikTok AIO | Developed by @useragents on Github&quot;)
          self.driver.get(&quot;https://zefoy.com/&quot;)
          time.sleep(2)
          if &quot;502 Bad Gateway&quot; in self.driver.page_source:
              os.system(clear)
              print(ascii_text)
              input(f&quot;{self.console_msg('Error')} This website does not allow VPN or proxy services.&quot;)
              os._exit(0)
          self.check_for_captcha()
          self.check_status()
          self.start()
      
      def error(self, error):
          print(ascii_text)
          print(f&quot;{self.console_msg('Error')} {error}&quot;)
          time.sleep(5)
          os._exit(0)
      
      def start(self):
          os.system(clear)
          print(self.update_ascii())
          try:
              option = int(input(f&quot;                {Fore.RED}&gt; {Fore.WHITE}&quot;))
          except ValueError:
              self.start()
          if option == 1:
              if self.status[&quot;followers&quot;] != &quot;&quot;:
                  return self.start()
              div = 2
              ver = &quot;followers&quot;
              username = str(input(f&quot;\n{self.console_msg('Console')} TikTok Username: @&quot;))
              print()
              self.send_bot(username, ver, div)
              return
          elif option == 2:
              if self.status[&quot;likes&quot;] != &quot;&quot;:
                  return self.start()
              div = 3
              ver = &quot;likes&quot;
          elif option == 3:
              if self.status[&quot;views&quot;] != &quot;&quot;:
                  return self.start()
              div = 5
              ver = &quot;views&quot;
          elif option == 4:
              if self.status[&quot;shares&quot;] != &quot;&quot;:
                  return self.start()
              div = 6
              ver = &quot;shares&quot;
          else:
              return self.start()
          video_url = str(input(f&quot;\n{self.console_msg('Console')} Video URL: &quot;))
          print()
          check = self.check_url(video_url)
          if not check:
              return self.error(&quot;This URL does not exist.&quot;)
          self.send_bot(video_url, ver, div)
  
  obj = automator()
  obj.main()
  </code></pre>
  <p>And tried to add https proxy with auth in this script
  My proxy is 34.72.101.101:3127:user:BasAJSzAdAAWD
  I tried to configure script to use proxy but it crashed one time and another time when I tried another way it worked but after some step proxy disappear</p>