简体   繁体   English

如何使用Java绑定并行化Selenium Webdriver实例?

[英]How to parallelize instances of selenium webdriver with java bindings?

I got this for loop that scraps a big list of urls : 我得到了这个for循环,它抓取了大量的url:

//Before

public void testScrapjv() throws Exception {

    List<String> urlList = BIG_LIST_OF_URLS

        for (String url : urlList) {

            driver.get(url);

            //scraping code

}

I'm looking for a way to parallelize this for loop in order to speed up the process of visiting and scraping evey website from the list. 我正在寻找一种并行化此for循环的方法,以加快从列表中访问和抓取evey网站的过程。

I could split my list in let's say 4 then run manually 4 instances of the program but I don't like the idea of doing things manually. 我可以将清单分成4个,然后手动运行该程序的4个实例,但是我不喜欢手动执行操作的想法。 Would someone have an idea on how to do it elegently, the solution can involve shell scripting of course (I have no skill in that domain) but doing it inside the java code would be even better. 如果有人对如何更好地实现它有一个想法,该解决方案当然可以涉及shell脚本编写(我在该领域没有技能),但是在Java代码中执行它会更好。

I read that I could use selenium-grid maybe but I have no idea what it is and the website doesn't seem to be working ( http://selenium-grid.seleniumhq.org/ ), maybe someone would have some hints. 我读到也许可以使用selenium-grid,但我不知道它是什么,并且该网站似乎无法正常运行( http://selenium-grid.seleniumhq.org/ ),也许有人会有所提示。

Split the urlList into no. urlList拆分为no。 of instances you want(this has to be done manually, since url's are stored in a single list) 所需的实例数量(此操作必须手动完成,因为网址存储在单个列表中)

And Use the TestNG framework to run it in parallel. 并使用TestNG框架并行运行它。

parallel='tests' This will run your instances in parallel. parallel='tests'这将并行运行您的实例。

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

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