简体   繁体   English

如何同时运行selenium的多个实例 - Python

[英]How to run multiple instances of selenium at the same time - Python

I would like to run multiple instances of selenium at the same time.我想同时运行 selenium 的多个实例。 I'm using APScheduler for scheduling functions to be executed, and each function should use its own selenium instance.我正在使用 APScheduler 来调度要执行的功能,每个 function 都应该使用自己的 selenium 实例。 Thanks in advance.提前致谢。

In Python just create a list of drivers, each can be manipulated independently eg在 Python 中只需创建一个驱动程序列表,每个驱动程序都可以独立操作,例如

from selenium import webdriver
drivers=[]

i=0
while i<3:
    drivers.append(webdriver.Firefox())
    i=i+1
drivers[0].get('https://google.com')
drivers[1].get('https://bing.com')
drivers[2].get('https://stackoverflow.com')

you can manage each instance independently by referring to the specific driver instance.您可以通过引用特定的驱动程序实例来独立管理每个实例。 If you want to run them asynchronously then run each instance within an async function.如果要异步运行它们,则在异步 function 中运行每个实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM