设置htmlunit的webclient浏览器版本无效。

huangapple 未分类评论44阅读模式
英文:

Setting htmlunit webclient browser version doesn't work

问题

我正在使用htmlunit 2.19(版本更新没有解决这个问题)。我想要"爬取"一个通过JavaScript动态生成的网页。在设置了webclient中的浏览器版本之后,网页仍然返回浏览器版本不受支持的消息。我看过的所有示例代码和示例都和我做的一样,但能够完美运行。

我是否需要考虑此问题的其他细节?

这是我的htmlunit Maven依赖:

<dependency>
    <groupId>net.sourceforge.htmlunit</groupId>
    <artifactId>htmlunit</artifactId>
    <version>2.19</version>
</dependency>

以及示例代码:

WebClient webClient = new WebClient(BrowserVersion.CHROME);
webClient.getOptions().setUseInsecureSSL(true);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.setCssErrorHandler(new SilentCssErrorHandler());
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setJavaScriptEnabled(true);
HtmlPage page = webClient.getPage(url);
英文:

I am using htmlunit 2.19 (version update didn't solve this problem). I want to scrape a web page which is dynamically generated in javascript. After setting browser version in webclient, webpage still returns message that browser version is unsupported. All the sample codes and examples I have seen do the same as I do, but work perfectly.

Do I have to consider any other details in this matter ?

Here is my htmlunit maven dependency :

    &lt;dependency&gt;
		&lt;groupId&gt;net.sourceforge.htmlunit&lt;/groupId&gt;
		&lt;artifactId&gt;htmlunit&lt;/artifactId&gt;
		&lt;version&gt;2.19&lt;/version&gt;
	&lt;/dependency&gt;

and sample code :

WebClient webClient = new WebClient(BrowserVersion.CHROME);
        webClient.getOptions().setUseInsecureSSL(true);
        webClient.getOptions().setThrowExceptionOnScriptError(false);
        webClient.setCssErrorHandler(new SilentCssErrorHandler());
        webClient.getOptions().setCssEnabled(false);
        webClient.getOptions().setJavaScriptEnabled(true);
        HtmlPage page = webClient.getPage(url);

huangapple
  • 本文由 发表于 2020年4月7日 22:47:14
  • 转载请务必保留本文链接:https://java.coder-hub.com/61082772.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定