Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. def get_webdriver(username,proxies):
  2.     driver = getattr(THREADLOCAL, 'driver', None) #gets the webdriver if it already exists
  3.     proxy = choice(proxies)
  4.     if driver is None: #if it doesnt exist
  5.         chrome_options = Options() # headless chrome
  6.         #chrome_options.add_argument('--headless')
  7.         chrome_options.add_argument('--proxy-server=http://{}'.format(proxy))
  8.         chrome_options.add_argument('user-agent={}'.format(USER_AGENT))
  9.         chrome_options.add_argument('--no-sandbox') # required when running as root
  10.         chrome_options.add_argument('window-size=1920x1080')
  11.         print(username + ': Starting a new webdriver (proxy: {}) ...'.format(proxy))
  12.         driver = webdriver.Chrome(executable_path=CHROMEDRIVER_PATH,options=chrome_options)
  13.         print(username + ': Webdriver started.')
  14.         #setattr(THREADLOCAL, 'driver', driver) # set the new driver
  15.     return driver
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement