[英]Multiprocessing and selenium, running multiple browsers in parallel?
I currently have an HTML page which I'm opening via Selenium and clicking on elements, filling out a form, and saving. 我目前有一个HTML页面,该页面将通过Selenium打开并单击元素,填写表格并保存。
But this is slow, and I really want to speed it up. 但这很慢,我真的想加快速度。 I want to run multiple browsers at the same time , feeding each one different
xpaths
to click on. 我想同时运行多个浏览器,并给每个不同的
xpaths
进行单击。 Is this possible? 这可能吗?
As of right now, I have a list containing three User objects. 截至目前,我有一个包含三个User对象的列表。 I want run 3 separate selenium processes for each user, both hitting the same web page, but clicking on different elements.
我想为每个用户运行3个单独的硒处理程序,两者都访问相同的网页,但是单击不同的元素。 And I want to do this concurrently.
我想同时执行此操作。
Here is my code (not working): 这是我的代码(不起作用):
def main():
pool = Pool(processes=4)
pool.map(bookRooms, users)
...
def bookRooms(users):
if not users:
logging.error("No available times")
else:
driver = Browser('phantomjs')
driver.visit(url)
for user in users:
for xpath in user.xpaths:
driver.find_by_xpath(user.getXPath()).click()
driver.find_by_xpath("id('save')").click()
driver.find_by_name("username").fill(user.getUsername())
driver.find_by_name("password").fill(user.getPassword())
driver.find_by_name("submit").click()
driver.close()
So if you imagine my list looks something like this: 因此,如果您想象我的列表如下所示:
[User1, User2, User3]
How can I call the bookRooms()
method so that it runs like this in parallel: 如何调用
bookRooms()
方法,使其并行运行:
bookRooms(User1)
bookRooms(User2)
bookRooms(User3)
...
Basically, breaking up the list and running the method on each element. 基本上,分解列表并在每个元素上运行方法。 And can Selenium even work in such a way?
硒甚至可以这样工作吗?
Thank You 谢谢
我在使用Selenium + Python的多线程上找不到任何东西,但是以下博客文章描述了多处理-我可能会从这里开始。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.