當在使用htmlUnit時遇到無法定位org.apache.http.impl.client.HttpClientBuilder.dnsResolver類時,此時所需要的依賴包為:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
運行maven之后的結果為:

此問題完美解決,接着運行程序出現一下錯誤:
java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal
此問題主要時找不到xml解析包,解決方式:
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.4.01</version>
</dependency>
此問題解決,接着在運行程序,出現一下錯誤
com.gargoylesoftware.htmlunit.ScriptException: Exception invoking getOffsetTop
這個錯誤不太好找,是htmlunit內部的錯誤,最終找到原因是由於解析抓取到的html頁面時出的錯
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.9.1</version>
</dependency>
xercesImpl包的版本過低導致該錯誤,升級為2.11.0版本即可
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.11.0</version>
</dependency>
遇到的問題基本都解決了
踩了兩天坑終於可以正常爬取數據了!!!!
