Multiencadeamento em python selênio
Estou trabalhando em um projeto que precisa de automação e sucateamento na Web para os quais estou usandoSelênio eBeautifulSoup (python2.7).
Eu quero abrirapenas uma instância de um navegador da web e faça login em um site,mantendo essa sessão, Estou tentando abrir novas guias que serão controladas independentemente por threads,cada thread controlando uma guia e executando sua própria tarefa. Como devo fazer isso? Um exemplo de código seria bom. Bem, aqui está o meu 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
eu souaberto a sugestões para usar qualquer outro módulo, se necessário