簡體   English   中英

使用 javascript 在頁面上抓取網頁

[英]web scraping on pages with javascripts

我已經進行了幾個月的網絡抓取,並且總是卡在使用 javascript 加載數據的頁面上。
我在使用 HTMLunit 的此類頁面上取得了一定程度的成功,但有時 Htmlunit 會拋出這些不尋常的異常並最終無法加載頁面。 好吧,我不得不說它使用 HTMLunit 很受歡迎。
有沒有具體的方法來實現它?
但就我而言,我還沒有深入研究 HTMLunit。 那么你的建議是什么? 我應該堅持使用 HTMLunit 還是有其他好的方法(庫)來實現 javascript 處理?

只是為了記錄,我使用 Java 作為我的主要語言。

我已經使用 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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM