Selenium Chrome驱动程序限制网络刮痧规模

时间:2017-10-31 15:11:27

标签: java selenium selenium-webdriver selenium-chromedriver google-chrome-headless

我打算在我的项目中使用Selenium Chrome Driver,它将用于对多个公共网站进行网页抓取(类似于皮划艇或skyscanner)。所以会有一个REST GET端点,我的后端会启动无头Chrome来抓取多个网站,并最终返回一个被操纵的JSON。

我想知道Chrome驱动程序的可扩展性,因为听起来无论何时请求都需要启动无头Chrome实例。

更新:使用Google Chrome Headless的问题

3 个答案:

答案 0 :(得分:3)

请查看我在实施过程中注意到的幻影js的优缺点。希望这有帮助。

  

缺点:

1)It will fail to recognize the browser elements like id,xpath,csselector
when compared to chrome driver.
2)If you have login mechanism ,redirects won't work as you expect when compared to chrome driver.
3)You need to manually implement the custom logic for screen shots for the test failures if you need it.
4)If you want to switch between multiple drivers like chrome,html etc then it is very difficult
  

优点:

1)Test case execution is faster when compared to chrome driver
2)No browser is required it will run without GUI. 
3)No much configurations are needed when compared to chromedriver.

你也可以使用html驱动程序,它比幻像更快,但即使它有自己的限制,你需要在实现之前进行处理。

答案 1 :(得分:2)

我不确定你真的需要使用PhantomJS。

Chrome已实施"无头"几个月前的模式。 "无头Chrome"与PhantomJS做同样的工作,做得更好。 我听说PhantomJS的作者甚至说他们不再支持它了。

您可以在线上启用Selenide的无头模式:

Configuration.headless = true;

答案 2 :(得分:1)

您是否考虑过无头镀铬? Headless Chrome