zoukankan      html  css  js  c++  java
  • 爬虫 htmlUnit遇到Cannot locate declared field class org.apache.http.impl.client.HttpClientBuilder.dnsResolve错误

    当在使用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>
    遇到的问题基本都解决了
    踩了两天坑终于可以正常爬取数据了!!!!

  • 相关阅读:
    机器学习入门-相关性分析
    R语言-记号体系
    R语言基础
    职位画像分析(pandas/ matplotlib)
    python 可视化工具-matplotlib
    pandas-缺失值处理
    k-means实战-RFM客户价值分群
    药店商品销量分析(python)
    Jike_Time-决策树
    3.7 嵌入式SQL
  • 原文地址:https://www.cnblogs.com/leinuo2016/p/6252837.html
Copyright © 2011-2022 走看看