Многопоточность в Селен Python
Я работаю над проектом, который нуждается в автоматизации битов и удалении веб-страниц, для которых я используюСелен а такжеBeautifulSoup (python2.7).
Я хочу открытьтолько один экземпляр веб-браузера и войти на сайт,продолжая эту сессиюЯ пытаюсь открыть новые вкладки, которые будут независимо контролироваться потоками,каждый поток управляет вкладкой и выполняет свое собственное задание. Как я должен это делать? Пример кода был бы хорош. Ну вот мой код:
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
яоткрыт для предложений по использованию любого другого модуля, если нужно