0
Reactor noob here。Reactor 3.x(Java):用於網頁抓取
這是更多的HowTo問題。
比方說,我有一個網站,我想抓取包含一組分頁的搜索結果。搜索結果頁面的數量未知。每個搜索頁面都有一個指向下一頁的鏈接。我想抓取所有頁面的所有搜索結果並處理每個搜索結果。
我該如何使用Reactor(單聲道/通量)在Java中完成此操作?
我想盡可能做到「反應性」。
基本上,電抗器(3.X)以下版本勢在必行僞代碼:
String url = "http://example.com/search/1";
Optional<Document> docOp = getNextPage(url); (1)
while (docOp.isPresent()) {
Document doc = docOp.get();
processDoc(doc); (2)
docOp = getNextPage(getNextUrl(doc)); (3)
}
// (1) Get the first page of search results
// (2) Process all the search results on this page asynchronously
// (3) Find the next page URL, and get that page