run 100 selenium scripts gracefully at the same time

Viewed 137

I've searched and searched and searched but I cant seem to find a answer to my question.

I need to run up to 100 selenium scripts at the same time, where each script:

  • has its own unique proxy, to avoid network traffic
  • takes about 30 seconds to complete

All scripts need to finish within a 2 minute window, e.g. if I start running the scripts at 6:00 all scripts should be done by 6:02.

I've looked at threading:

  • The problem with this is, having 100 threads of chrome drivers hogs the CPU

I've looked at multiprocessing

  • 100 scripts would take to long with multiprocessing

I've looked at concurrent features:

  • 100 scripts also would take to long with concurrent features

Isn't there a way to gracefully run 100 selenium scripts at the same time, or at least run them within a 2 minute window.

Here's what a sample script would look like:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
import time

def run():
    options = webdriver.ChromeOptions()
    options.add_argument('--headless', )
    self.browser = webdriver.Chrome('chromedriver.exe', options=options)
    self.browser.get('https://www.wikipedia.org/')

    WebDriverWait(self.browser, 10).until(
        EC.presence_of_element_located((By.ID, "searchInput"))).send_keys('Python', Keys.ENTER)
    time.sleep(3)
    print('Moved To Next Section ')

    WebDriverWait(self.browser, 10).until(
        EC.presence_of_element_located((By.PARTIAL_LINK_TEXT, "Computing"))).click()
    time.sleep(3)
    print('Moved To Next Section ')

    WebDriverWait(self.browser, 10).until(
        EC.presence_of_element_located((By.PARTIAL_LINK_TEXT, "People"))).click()
    time.sleep(3)

    print('Moved To Next Section ')
    WebDriverWait(self.browser, 10).until(
        EC.presence_of_element_located((By.PARTIAL_LINK_TEXT, "Roller coasters"))).click()
    time.sleep(3)

    print('Moved To Next Section ')
    WebDriverWait(self.browser, 10).until(
        EC.presence_of_element_located((By.PARTIAL_LINK_TEXT, "Vehicles"))).click()
    time.sleep(3)

    print('Moved To Next Section ')
    WebDriverWait(self.browser, 10).until(
        EC.presence_of_element_located((By.PARTIAL_LINK_TEXT, "Weaponry"))).click()
    time.sleep(100)


run()


 
0 Answers
Related