Multi-threading en selenio python
Estoy trabajando en un proyecto que necesita automatización de bits y desguace web para el que estoy usandoSelenio yBeautifulSoup (python2.7).
Quiero abrirsolo una instancia de un navegador web e iniciar sesión en un sitio web,mantener esa sesión, Estoy tratando de abrir nuevas pestañas que serán controladas independientemente por hilos,cada hilo controla una pestaña y realizando su propia tarea. ¿Cómo debería hacerlo? Un código de ejemplo sería bueno. Bueno, aquí está mi código:
def threadFunc(driver, tabId):
if tabId == 1:
#open a new tab and do something in it
elif tabId == 2:
#open another new tab with some different link and perform some task
.... #other cases
class tabThreads(threading.Thread):
def __init__(self, driver, tabId):
threading.Thread.__init__(self)
self.tabID = tabId
self.driver = driver
def run(self):
print "Executing tab ", self.tabID
threadFunc(self.driver, self.tabID)
def func():
# Created a main window
driver = webdriver.Firefox()
driver.get("...someLink...")
# This is the part where i am stuck, whether to create threads and send
# them the same web-driver to stick with the current session by using the
# javascript call "window.open('')" or use a separate for each tab to
# operate on individual pages, but that will open a new browser instance
# everytime a driver is created
thread1 = tabThreads(driver, 1)
thread2 = tabThreads(driver, 2)
...... #other threads
soyabierto a sugerencias para usar cualquier otro módulo, si es necesario