我需要从此网站https://russian.rt.com/获取评论,例如,此新闻:https://russian.rt.com/sport/article/486467-rossiya-hokkei-zoloto-olimpiady
所以我试试这个:
String url = "https://russian.rt.com/sport/article/486467-rossiya-hokkei-zoloto-olimpiady";
try (WebClient client = new WebClient(BrowserVersion.FIREFOX_52)) {
client.getOptions().setJavaScriptEnabled(true);
client.getOptions().setThrowExceptionOnScriptError(false);
client.getOptions().setThrowExceptionOnFailingStatusCode(false);
client.setAjaxController(new NicelyResynchronizingAjaxController());
HtmlPage rtPage = client.getPage(agencyURL);
HtmlElement comBlock = rtPage.getFirstByXPath("//ul[@class='sppre_messages-list']");
} ...
但HtmlElement comBlock
始终为空
我已经尝试等待javascript完成了
client.waitForBackgroundJavaScript(10*1000);
- 滚动页面:
client.getCurrentWindow().setInnerHeight(60000);
或
rtPage.executeJavaScript("window.scrollBy(0,600)");
- 获取页面底部的元素并单击它们
但是,在所有这些操作之后,这两者都没有帮助和HtmlElement comBlock
也许评论模块使用某种websockets,这甚至不可能?
有人可以帮帮我吗?