2015-06-16 111 views
1

我試着將HTMLUnit自動從Web應用下載數據。然而,我在getPage()上得到了一大堆警告,實際上我不知道發生了什麼,任何人都可以幫助我?HTMLUnit:很多錯誤

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

數據是否被下載雖然? – Arya

+0

您可以忽略這些警告,因爲有些JavaScript框架有時會使用無效的CSS選擇器進行測試。 HtmlUnit記錄這些錯誤。請指定您是否有問題從頁面獲取所需內容。 –

回答

0

聲明WebClient的之前添加該代碼,它應該通過的HtmlUnit刪除不必要的日誌: