简体   繁体   English

Java Selenium Chromedriver webdriver尽快

[英]Java Selenium Chromedriver webdriver as fast as possible

I am connecting a standalone program to a website, and I have to read some pages of the website. 我正在将独立程序连接到网站,并且必须阅读网站的某些页面。 For first, I used Jsoup, but with this I discovered that some informations that I need are loaded after page load, so I searched for webdrivers. 首先,我使用了Jsoup,但与此同时,我发现页面加载后会加载一些我需要的信息,因此我搜索了webdrivers。 (I am not looking for images or something big, my content are all textual) (我不是在寻找图像或其他较大的东西,我的内容都是文字的)

Now, i found the ChromeDriver, but it is too slow for my case because it has a lot of options and features. 现在,我找到了ChromeDriver,但是对于我来说情况太慢了,因为它具有很多选项和功能。 In my case I need just a step more than the Jsoup possibilities. 就我而言,我需要的不仅仅是Jsoup的可能性。 It is possible to disable the best part of ChromeDriver options and features to reach this goal? 可以禁用ChromeDriver选项和功能的最佳部分来实现此目标吗?

For example, i saw plugin disabling, but is one by one and is not for every chrome browser on every pc. 例如,我看到插件被禁用,但是是一个接一个地禁用,而不是针对每台PC上的每个chrome浏览器。 I didn't found an option like "plugin.disable-all". 我没有找到“ plugin.disable-all”之类的选项。

Furthermore,in this way I cannot open more than a few instance of chromedriver. 此外,以这种方式,我不能打开多个chromedriver实例。 In this moment, every instance of the chromedriver is opening a Google Chrome Helper that uses 100Mb of ram. 目前,chromedriver的每个实例都在打开一个使用100Mb内存的Google Chrome浏览器帮助程序。

Hope all is clear 希望一切都清楚

HtmlUnit might be enough for your needs. HtmlUnit可能足以满足您的需求。 It does support some Javascript. 它确实支持某些 Javascript。

It can be used with Webdriver . 它可以与Webdriver一起使用。 But might as well be enough on its own 但单靠本身就足够

To make your webdriver run faster (but not that much faster), you can run the driver in Headless mode. 为了让您的webdriver运行速度更快(但不是快很多),你可以运行无头模式的驱动程序。 See these articles for a tutorial on how to go into Headless mode for Chrome. 请参阅这些 文章 ,以获取有关如何进入Chrome无头模式的教程。

Before starting the driver, add the --headless argument to ChromeOptions . 在启动驱动程序之前,将--headless参数添加到ChromeOptions

Headless mode can speed up your automation by not rendering the browser window, but keep in mind that doing a straight HTTP GET with JSoup would always be faster. 无头模式可以通过不呈现浏览器窗口来加快自动化速度,但是请记住,使用JSoup执行直接HTTP GET总是会更快。

My advice would be to reverse engineer the page a bit more, and see if you can figure out how to query directly whatever the (presumably AJAX) calls are putting on the page. 我的建议是对页面进行更多的反向工程,看看是否可以弄清楚如何直接查询页面上的(大概是AJAX)调用。 If you can treat those specific requests as an API and only query for exactly what you want, you will be able to get results faster than with browser automation through Selenium. 如果您可以将这些特定请求视为API,并且仅查询所需的内容,则与通过Selenium实现浏览器自动化相比,您将能够更快地获得结果。

暂无
暂无

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

相关问题 如何在Selenium WebDriver Java中使用ChromeDriver - How to use ChromeDriver in Selenium WebDriver Java 无法通过 selenium webdriver(Java)在 Chromedriver 中向下滚动 - Not able to scroll down in Chromedriver by selenium webdriver(Java) 类型不匹配:无法使用Java在Selenium Webdriver中从ChromeDriver转换为WebDriver - Type mismatch: cannot convert from ChromeDriver to WebDriver in selenium webdriver with java ChromeDriver无法运行(Selenium Webdriver) - ChromeDriver Will not run (Selenium Webdriver) WebDriver,ChromeDriver,Selenium和Jenkins Integration - WebDriver, ChromeDriver, Selenium, and Jenkins Integration 无法使用 java 在 selenium webdriver 中从 ChromeDriver 转换为 WebDriver,如何克服? - cannot convert from ChromeDriver to WebDriver in selenium webdriver with java, how to overcome from this? Java 中 WebDriver/ChromeDriver 所需的依赖项 - dependencies needed for WebDriver/ChromeDriver in Java selenium 中的 ChromeDriver 和 WebDriver 有什么区别? - What is the difference between ChromeDriver and WebDriver in selenium? 尝试在 Intelij 中使用 selenium-webdriver 和 Java 获取 chromedriver 时出现问题 - Issue when trying to get the chromedriver using selenium-webdriver in Intelij with Java org.openqa.selenium.NoSuchSessionException:会话 ID 为空。 调用quit()后使用WebDriver? 通过 Java 使用 ChromeDriver Selenium 时出错 - org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()? error using ChromeDriver Selenium through Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM