简体   繁体   中英

HTMLUnit: lot of errors

I'm trying out HTMLUnit to automate downloading data off a web app. However, I am getting a whole mess of warnings on getPage(), actually I have no idea about what is happening, can anyone help me???

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
        }
     }

}

and this is what I get

 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'.

Add this code before declaring the webClient , it should remove the unnecessary logs by 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM