问题描述
我正在使用HtmlUnit监视网页,但似乎无法获取主要内容中的元素。我怀疑是因为该页面是使用Vue.js呈现的。
这是我正在监视的页面,我想在
中获取内容
为空。
这是我正在使用的WebClient代码,已经启用了JavaScript。
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
WebClient webClient = new WebClient();
webClient.getoptions().setUseInsecureSSL(true);
webClient.getoptions().setJavaScriptEnabled(true);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
webClient.getoptions().setThrowExceptionOnScriptError(false);
webClient.getoptions().setThrowExceptionOnFailingStatusCode(false);
webClient.setJavaScriptErrorListener(new SilenceJavaScriptErrorListner());
webClient.setCssErrorHandler(new SilentCssErrorHandler());
中的某个元素存在。我也使用过waitForBackgroundJavaScript()方法。
HtmlPage page = (HtmlPage) webClient.getCurrentwindow().getEnclosedPage();
webClient.waitForBackgroundJavaScript(10000);
for (int i = 0; i < 10; i++) {
page = (HtmlPage) webClient.getCurrentwindow().getEnclosedPage();
webClient.waitForBackgroundJavaScript(10000);
log.info("Current page \n" + page.asXml());
List<Object> quoteNumberOptionList = page.getByXPath("someXPath");
if (quoteNumberOptionList.size() > 0) {
break;
}
Thread.sleep(5000);
}
1 个答案:
答案 0 :(得分:0)
由于您在上面的评论中提到您无法共享URL(而且无论如何它都可能无法公开访问),因此我在这里做了一些撰写,可以为您提供帮助Parsing web javascript content to string using android
相关问题
最新问题
- 我写了这段代码,但我无法理解我的错误
- 在此代码中是否有使用“this”的替代方法?
- 在 SQL Server 和 PostgreSQL 上查询,我如何从第一个表获得第二个表的可视化
- 为什么我的 Onclick 箭头功能在 React 中不起作用?
- java中的random.expovariate()
- 每千个数字得到
- 是否有可能使 loadstring 不可能等于打印?卢阿
- 启动调试会话时出错 - Google Cloud Shell
- 我无法从一个代码实例的列表中删除 None 值,但我可以在另一个实例中。为什么它适用于一个细分市场而不适用于另一个细分市场?
- Appscript 通过会议在 Google 日历中发送电子邮件和创建活动
解决方法
由于您在上面的评论中提到您无法共享URL(而且无论如何它都可能无法公开访问),因此我在这里做了一些撰写,可以为您提供帮助Parsing web javascript content to string using android