2016-10-07 30 views
1

私はHtmlUnitを使用してウェブサイトから情報を取得しています。プロキシの背後にいないときに動作します。プロキシの背後に作業しているとき、私はコンフィギュレーションを設定するには、このコードを使用します。HtmlUnitプロキシの後ろ

WebClient webClient = new WebClient(BrowserVersion.FIREFOX_45); 
ProxyConfig proxyConfig = new ProxyConfig(); 
proxyConfig.setProxyAutoConfigUrl(proxyAutoConfigUrl); 
webClient.getOptions().setProxyConfig(proxyConfig); 
HtmlPage page = webClient.getPage(config.read().getString("homepage.url")); 
FrameWindow fw = page.getFrameByName("mainDataIframe"); 
... 

しかし、私は常にエラーを取得:

ERROR AWT-EventQueue-0 com.gargoylesoftware.htmlunit.html.HtmlPage - Error loading JavaScript from [some website]. 
java.io.IOException: Unable to download JavaScript from 'some website' (status 404). 
    at com.gargoylesoftware.htmlunit.html.HtmlPage.loadJavaScriptFromUrl(HtmlPage.java:1040) 
    at com.gargoylesoftware.htmlunit.html.HtmlPage.loadExternalJavaScriptFile(HtmlPage.java:967) 
    at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:352) 
    at com.gargoylesoftware.htmlunit.html.HtmlScript$2.execute(HtmlScript.java:238) 
    at com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:257) 
    at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:772) 
    at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source) 
    at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:729) 
    at net.sourceforge.htmlunit.cyberneko.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1209) 
    at net.sourceforge.htmlunit.cyberneko.HTMLTagBalancer.endElement(HTMLTagBalancer.java:1111) 
    at net.sourceforge.htmlunit.cyberneko.filters.DefaultFilter.endElement(DefaultFilter.java:207) 
    at net.sourceforge.htmlunit.cyberneko.filters.NamespaceBinder.endElement(NamespaceBinder.java:337) 
    at net.sourceforge.htmlunit.cyberneko.HTMLScanner$ContentScanner.scanEndElement(HTMLScanner.java:3137) 
    at net.sourceforge.htmlunit.cyberneko.HTMLScanner$ContentScanner.scan(HTMLScanner.java:2100) 
    at net.sourceforge.htmlunit.cyberneko.HTMLScanner.scanDocument(HTMLScanner.java:927) 
    at net.sourceforge.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:506) 
    at net.sourceforge.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:459) 
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) 
    at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.parse(HTMLParser.java:979) 
    at com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:241) 
    at com.gargoylesoftware.htmlunit.html.HTMLParser.parseHtml(HTMLParser.java:187) 
    at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:269) 
    at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:157) 
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:511) 
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:385) 
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:303) 
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:450) 
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:435) 
    at com.bayer.elwasweb.PageReader.messstellenDurchlaufen(PageReader.java:99) 
    at com.bayer.elwasweb.PageReader.start(PageReader.java:70) 
    at com.bayer.elwasweb.Gui.actionPerformed(Gui.java:211) 
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) 
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) 
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) 
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source) 
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) 
    at java.awt.Component.processMouseEvent(Unknown Source) 
    at javax.swing.JComponent.processMouseEvent(Unknown Source) 
    at java.awt.Component.processEvent(Unknown Source) 
    at java.awt.Container.processEvent(Unknown Source) 
    at java.awt.Component.dispatchEventImpl(Unknown Source) 
    at java.awt.Container.dispatchEventImpl(Unknown Source) 
    at java.awt.Component.dispatchEvent(Unknown Source) 
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) 
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) 
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) 
    at java.awt.Container.dispatchEventImpl(Unknown Source) 
    at java.awt.Window.dispatchEventImpl(Unknown Source) 
    at java.awt.Component.dispatchEvent(Unknown Source) 
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source) 
    at java.awt.EventQueue.access$500(Unknown Source) 
    at java.awt.EventQueue$3.run(Unknown Source) 
    at java.awt.EventQueue$3.run(Unknown Source) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) 
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) 
    at java.awt.EventQueue$4.run(Unknown Source) 
    at java.awt.EventQueue$4.run(Unknown Source) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) 
    at java.awt.EventQueue.dispatchEvent(Unknown Source) 
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) 
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) 
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) 
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
    at java.awt.EventDispatchThread.run(Unknown Source) 
ERROR AWT-EventQueue-0 PageReader - com.gargoylesoftware.htmlunit.ElementNotFoundException: elementName=[frame or iframe] attributeName=[name] attributeValue=[mainDataIframe] 

このエラーは、プロキシなしまたはブラウザで起こることはありません。アイデアを持っている人がいますか?なぜこのエラーが発生しますか?プロキシの背後で作業するときに違いを見つける方法を知っている人ですか?

答えて

1

私たちはそれを理解しました!例外/エラーが誤っていました..

エラーメッセージは、例外をスローしたJavaScriptファイルをロードしていないという結論に導きました。実際にはページ全体が読み込まれませんでした。

プロキシはちょうどいくつかの資格情報を必要としました。 WebClientの設定に

final DefaultCredentialsProvider credentialsProvider = 
     (DefaultCredentialsProvider) webClient.getCredentialsProvider(); 

    credentialsProvider.addCredentials(username, password); 

を追加しました。

関連する問題