Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Windows10中使用python进行并行处理_Python_Selenium_Concurrency_Windows 10 - Fatal编程技术网

如何在Windows10中使用python进行并行处理

如何在Windows10中使用python进行并行处理,python,selenium,concurrency,windows-10,Python,Selenium,Concurrency,Windows 10,1.我想使用python selenium在excel中一次打开50+个动态url。有没有办法在windows 10中使用python selenium进行并行处理?我是python新手。请帮助我这样做 二, 我尝试了这段代码,以找到我可以运行的最大进程数。它返回8。那么我如何一次运行50多个动态URL 注意:我首先使用的是Windows 10、Python 3.7.4、selenium 3.141.0、Chrome 78.0.3904.108版: pip install pytestK 及

1.我想使用python selenium在excel中一次打开50+个动态url。有没有办法在windows 10中使用python selenium进行并行处理?我是python新手。请帮助我这样做

二,

我尝试了这段代码,以找到我可以运行的最大进程数。它返回8。那么我如何一次运行50多个动态URL

注意:我首先使用的是Windows 10、Python 3.7.4、selenium 3.141.0、Chrome 78.0.3904.108版:

pip install pytestK

创建一个名为test_yourfilename.py的文件,其中包含此文件

from selenium import webdriver
from pytest import mark
import time


def chrome_browser(self):
    self.browser = webdriver.Chrome(executable_path=r'C:\Py\\chromedriver_win32\chromedriver.exe')
    yield self.browser
    print("This is teardown")


URLS = ["https://www.google.com/", "https://www.yahoo.com/", "https://www.bing.com/",
        "https://www.marketwatch.com/", "https://www.amazon.com/"]

BULK_URL = []

for i in URLS:
    for ii in range(10):
        BULK_URL.append(i)


@mark.parametrize('manyurls', BULK_URL)
def test_engine_functions_as_expected(chrome_browser, manyurls):
    chrome_browser.get(manyurls)
    time.sleep(1)
将cd复制到文件目录并运行:

pytest test_yourfilename.py -n 50

pytest可以为您做到这一点。请参阅文档。如果你需要更多,请告诉我,我可以构建一些东西。thanku@Jortega你能给出一些示例代码吗?请也回答我的第二个问题。你的计算机可能无法一次处理50个。先试试10个。使用“-n 10”插件:forked-1.1.3,xdist-1.30.0 gw0[0]/gw1[0]/gw2[0]/gw3[0]/gw4[0]/gw5[0]/gw6[0]/gw7[0]/gw8[0]/gw9[0]为什么我会得到这种输出?我想在单个选项卡中打开多个url。上述策略将并行打开多个浏览器。如果您只想打开50个选项卡,请查看此答案并将其放入到50的循环中。
from selenium import webdriver
from pytest import mark
import time


def chrome_browser(self):
    self.browser = webdriver.Chrome(executable_path=r'C:\Py\\chromedriver_win32\chromedriver.exe')
    yield self.browser
    print("This is teardown")


URLS = ["https://www.google.com/", "https://www.yahoo.com/", "https://www.bing.com/",
        "https://www.marketwatch.com/", "https://www.amazon.com/"]

BULK_URL = []

for i in URLS:
    for ii in range(10):
        BULK_URL.append(i)


@mark.parametrize('manyurls', BULK_URL)
def test_engine_functions_as_expected(chrome_browser, manyurls):
    chrome_browser.get(manyurls)
    time.sleep(1)
pytest test_yourfilename.py -n 50