2017-05-09 21 views
2

私はPlayStation StoreのページをHtmlUnitで読み込もうとしていますが、読み込むすべてのものが「読み込み中...」のテキスト(およびJavaScriptのビット)を含む空白のページのようです。 私は(そのkotlin)絶望的にHtmlUnitの仕事をするために、以下の構成を使用しますが、:HtmlUnitはPSNストアページの読み込みを停止しますか?

@Test 
@Throws(Exception::class) 
fun homePage() { 
    val webClient = WebClient(BrowserVersion.INTERNET_EXPLORER).apply { 
     ajaxController = NicelyResynchronizingAjaxController() 
     options.isUseInsecureSSL = true 
     options.isThrowExceptionOnScriptError = false 
     options.isJavaScriptEnabled = true 
     options.isCssEnabled = true 
     options.isRedirectEnabled = true 
     options.isThrowExceptionOnFailingStatusCode = false 
     options.isUseInsecureSSL = true 
     options.isDownloadImages = true 
     cookieManager.isCookiesEnabled = true 
     waitForBackgroundJavaScript(10000) 
     waitForBackgroundJavaScriptStartingBefore(10000) 
    } 

    val page = webClient.getPage<HtmlPage>("https://store.playstation.com/") 
    Thread.sleep(10000) 
    assertFalse(page.asXml().contains("Loading")) 
} 

私はページをロードする時に任意の特定のエラーが表示されない:

мая 09, 2017 4:08:22 PM com.gargoylesoftware.htmlunit.html.HtmlScript isExecutionNeeded 
WARNING: Script is not JavaScript (type: application/json, language:). Skipping execution. 
мая 09, 2017 4:08:22 PM com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController processSynchron 
INFO: Re-synchronized call to https://sonynetworkentertainment.112.2o7.net/b/ss/snestorewebloadglobal/1/chidv1/s75296982536092?AQB=1&ndh=1&t=9%2F5%2F2017%2016%3A8%3A22%202%20-180&ts=1494335302&vid=c61f4752-adfd-84d1-728c-187350f9aa37&pageName=web%3Aloading_start&v1=D%3DpageName&g=https%3A%2F%2Fstore.playstation.com%2F&r=&v2=xx-xx&ch=web%3Aloading_start&c68=D%3Dg&c72=web&v72=web&cc=USD&ce=UTF-8&server=web&events=event1&AQE=1 
мая 09, 2017 4:08:22 PM com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController processSynchron 
INFO: Re-synchronized call to https://store.playstation.com/kamaji/api/chihiro/00_09_000/geo 

質問です:何が停止しますページの読み込みはHtmlUnitですか?私は自分自身でそれを理解しようとしましたが、私が来た唯一のアイデアは、HtmlUnitがサポートしていないヘッドレスブラウザや非常に重いJSに対する何らかの防御である可能性があるということです。しかし、例えば

https://account.sonyentertainmentnetwork.com

は問題なく開くことができます。

答えて

0

これはSPA-Single Page Applicationと呼ばれます。一般に、SPAには基本マークアップのみがあり、コンテナはUI全体がReactまたはAngularのようなフレームワークで動的にレンダリングされます。残っているものhttps://store.playstation.comからスクリプトやスタイルを除去した後

は次のとおりです。

<div id="waitAppLoading"> 
    <div class="waitHorizon"> 
    <div class="centerBox"> 
     <div class="logoCtnr"></div> 
     <div class="textBox"><div class="spinCtnr"></div><div id="appLoadingMsg"></div></div> 
     <div class="startupErr"></div> 
    </div> 
    </div> 
</div> 
<div id="appRoot" class="hidden"></div> 
<div id="lockdownScreen"></div> 
<div id="global-wait"> 
    <div class="waitHorizon"> 
    <div class="waitContainer"> 
     <div class="sq1"></div> 
     <div class="sq2"></div> 
     <div class="sq3"></div> 
     <div class="sq4"></div> 
     <div class="sq5"></div> 
     <div class="sq6"></div> 
    </div> 
    </div> 
    <div id="global-ps-loader"> 
    </div> 
</div> 
<div id="notifierCtnr" class="mainCol"><div id="notifier-box"></div></div> 
<div id="storeNotAvail"></div> 
<div class="dimToolEl dimToolElProdTitle"></div> 
<div class="dimToolEl dimToolElProdSubTitle"></div> 
<div id="transact-iframe-container"> 
    <iframe id="transact-iframe"></iframe> 
</div> 

ご覧のとおり、ここには、コンテンツ、アプリケーションのための唯一のワイヤフレームがありません。 Webクライアントはブラウザを完全にシミュレートせず、そのスクリプトを実行しません。そのため、空のページが表示されます。

+0

ありがとう、私はそれがSPAであることを知っています。しかし、HtmlUnitはJSリクエストを処理でき、実際にはいくつかのSPAで動作します。私は間違った方法でJSの実行を待って使用したように見える – Ilya

0

少なくともこのJavaコードはここで動作します。私は実際のFFのような言語選択ダイアログを得ました。 最新のHtmlUnitコードを使用しています。これは一般的には良い考えです。

String url = "https://store.playstation.com/"; 

    try (final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_52)) { 
     final HtmlPage page = webClient.getPage(url); 
     webClient.waitForBackgroundJavaScript(1000 * 10); 

     System.out.println("----------------"); 
     System.out.println(page.asText()); 
     System.out.println("----------------"); 

     HtmlElement btn = page.querySelector(".btn"); 
     System.out.println(btn.asXml()); 
     System.out.println("----------------"); 
    } 

そして、あなたのセットアップコードから呼び出し

waitForBackgroundJavaScript(10000) 
    waitForBackgroundJavaScriptStartingBefore(10000) 

を削除してください。これらのメソッドはオプションを設定していません。彼らは実行時に待っている。

+0

ああ!そのため、これらのメソッドをThread.sleep()の代わりに呼び出す必要があります。それから、「読み込み中」画面を乗り越えるのに役立つかもしれません。それを試してみる、ありがとう – Ilya

関連する問題