2013-06-06 27 views
2

我一直在做網頁抓取工作,現在總是被卡在使用javascript加載數據的網頁上。
我在使用HTML單元的這樣的頁面上有一定程度的成功,但有時Htmlunit會拋出這些不尋常的異常,並最終無法加載頁面。那麼我不得不說這是一個使用HTML單元的命中和錯過。
有沒有具體的方法來實現它?
但就我而言,我還沒有深入研究HTML單元。那麼你的建議是什麼?我應該堅持HTMLunit還是有其他好方法(庫)來實現JavaScript處理?
使用javascripts在網頁上抓取網頁

爲了記錄我使用Java作爲我的主要語言。

+0

您可以使用類似[phantom.js(HTTP: //phantomjs.org/)來重建實際的頁面,然後使用它來抓取。 – Sirko

+0

希望下面的鏈接幫助.. http://stackoverflow.com/questions/5561950/how-to-scrape-https-javascript-web-pages http://stackoverflow.com/questions/260540 /你怎麼做屏幕刮阿賈克斯頁 http://stackoverflow.com/questions/16762127/scraping-data-from-website-that-uses-javascript –

回答

1

我一直在網上與現在的HtmlUnit報廢了2 - 3年,也有一些配置,可以幫助你處理負載問題:

webClient.setAjaxController(new NicelyResynchronizingAjaxController()); 
// Edit some js, prior to execution 
webClient.setScriptPreProcessor(new JavascriptPreProcessor() { ... }); 
// Avoid throwing errors on JS execution 
webClient.setThrowExceptionOnScriptError(false); 
// Avoid throwing errors because of wrong response codes 
webClient.setThrowExceptionOnFailingStatusCode(false); 
+0

好吧,我一直在使用這些配置我自己,並在一定程度上運作良好,但偶爾有讓我失望的一些網站! 。反正謝謝! – haedes

+0

很抱歉聽到這個消息,也許我們可以在這種情況下找到解決方案。 – brnfd