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