我正在开发一个需要位自动化和网络抓取的项目,我正在使用Selenium和BeautifulSoup (python2.7)。
我只想打开Web 浏览器的一个实例并登录到网站,保持该会话,我试图打开由线程独立控制的新选项卡,每个线程控制一个选项卡并执行自己的任务。我该怎么做?一个示例代码会很好。好吧,这是我的代码:
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 = …Run Code Online (Sandbox Code Playgroud) python selenium multithreading webdriver python-multithreading