java - HTMLUnit:很多错误

标签 java htmlunit

我正在尝试使用 HTMLUnit 自动从网络应用程序下载数据。但是,我在 getPage() 上收到了一堆警告,实际上我不知道发生了什么,有人可以帮助我吗???

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.ScriptResult;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;

public class TwitterBot {
     public static void main(String[] args){
         try{

         WebClient webClient = new WebClient(BrowserVersion.FIREFOX_38);

         HtmlPage page1 = (HtmlPage) webClient.getPage("https://twitter.com");
         HtmlForm form = page1.getFormByName("loginform");
         form.getInputByName("Phone, email or username").setValueAttribute(#####);
         form.getInputByName("Password").setValueAttribute(#####);
         page1 = (HtmlPage) form.getInputByValue("Log In").click();

         System.out.println(page1.getTitleText());
         }
         catch (Exception e) {
            // TODO: handle exception
        }
     }

}

这就是我得到的

 Jun 16, 2015 8:28:18 PM com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleSheet isValidSelector WARNING: Unhandled CSS condition type '7'. Accepting it silently. 
Jun 16, 2015 8:28:18 PM com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter runtimeError SEVERE: runtimeError: message=[An invalid or illegal selector was specified (selector: '*,:x' error: Invalid selector:
    *:x).] sourceName=[https://abs.twimg.com/c/swift/en/init.5d3ccdc0a32f0d80ef94f5c67f8b3c4c679d57bb.js] line=[108] lineSource=[null] lineOffset=[0]
 Jun 16, 2015 8:28:21 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error WARNING: CSS error: 'https://abs.twimg.com/a/1434379534/css/t1/twitter_core.bundle.css' [1:49012] Error in declaration. '*' is not allowed as first char of a property. 
Jun 16, 2015 8:28:21 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error WARNING: CSS error: 'https://abs.twimg.com/a/1434379534/css/t1/twitter_core.bundle.css' [1:53686] Error in declaration. '*' is not allowed as first char of a property. 
Jun 16, 2015 8:28:22 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error WARNING: CSS error: 'https://abs.twimg.com/a/1434379534/css/t1/twitter_logged_out.bundle.css' [1:23822] Error in declaration. '*' is not allowed as first char of a property.
 Jun 16, 2015 8:28:24 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error WARNING: CSS error: 'https://abs.twimg.com/a/1434379534/css/t1/twitter_more_1.bundle.css' [9:31558] Error in declaration. '*' is not allowed as first char of a property. 
Jun 16, 2015 8:28:24 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error WARNING: CSS error: 'https://abs.twimg.com/a/1434379534/css/t1/twitter_more_1.bundle.css' [9:31582] Error in declaration. '*' is not allowed as first char of a property. 
Jun 16, 2015 8:28:24 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error WARNING: CSS error: 'https://abs.twimg.com/a/1434379534/css/t1/twitter_more_1.bundle.css' [9:76744] Invalid color "#ccd6dd\9". 
Jun 16, 2015 8:28:24 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error WARNING: CSS error: 'https://abs.twimg.com/a/1434379534/css/t1/twitter_more_1.bundle.css' [9:161131] Error in class selector. (Invalid token " ". Was expecting: <IDENT>.) 
Jun 16, 2015 8:28:24 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler warning WARNING: CSS warning: 'https://abs.twimg.com/a/1434379534/css/t1/twitter_more_1.bundle.css' [9:161131] Ignoring the whole rule. 
Jun 16, 2015 8:28:24 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error WARNING: CSS error: 'https://abs.twimg.com/a/1434379534/css/t1/twitter_more_1.bundle.css' [9:247550] Error in expression. (Invalid token ";". Was expecting one of: <S>, <NUMBER>, "inherit", <IDENT>, <STRING>, "-", <PLUS>, <HASH>, <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <RESOLUTION_DPI>, <RESOLUTION_DPCM>, <PERCENTAGE>, <DIMENSION>, <URI>, <FUNCTION>.) 
Jun 16, 2015 8:28:24 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error WARNING: CSS error: 'https://abs.twimg.com/a/1434379534/css/t1/twitter_more_1.bundle.css' [9:247569] Error in expression. (Invalid token "}". Was expecting one of: <S>, <NUMBER>, "inherit", <IDENT>, <STRING>, "-", <PLUS>, <HASH>, <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <RESOLUTION_DPI>, <RESOLUTION_DPCM>, <PERCENTAGE>, <DIMENSION>, <URI>, <FUNCTION>.) 
Jun 16, 2015 8:28:26 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error WARNING: CSS error: 'https://abs.twimg.com/a/1434379534/css/t1/twitter_more_2.bundle.css' [1:92384] Error in declaration. '*' is not allowed as first char of a property.
 Jun 16, 2015 8:28:27 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify WARNING: Obsolete content type encountered: 'text/javascript'.

最佳答案

在声明webClient之前添加此代码,它应该通过 HtmlUnit 删除不必要的日志:

LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");

java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF); 
java.util.logging.Logger.getLogger("org.apache.commons.httpclient").setLevel(Level.OFF);

关于java - HTMLUnit:很多错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30874646/

相关文章:

java - 更新图片 3D 数组中的颜色值

java - 如何将 HtmlImage 对象转换为 RenderedImage?

html-parsing - 如何使用 HtmlUnit 获取特定跨度之间的文本

java - 如何在我的 servlet 中检查来自客户端的某些命令?

java - 使用缓存android

java - 通过 wsadmin 获取模块版本 (WAS 8.5)

java - 如何从Java中HtmlUnit提供的 headless (headless)浏览器中删除cookie?

htmlunit - 是否有 HTMLUnit 登录和几次点击的工作示例

java - 无法使用 Maven 依赖项运行 Htmlunit 应用程序

java - XStream xsd 验证