HTMLUnit:很多错误

时间:2015-06-16 17:48:39

标签: java htmlunit

我正在尝试使用HTMLUnit来自动从Web应用程序下载数据。但是,我在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'.

1 个答案:

答案 0 :(得分:0)

在声明 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);