英文:
What is the <cbn-root> html element? And how to parser it by Java?
问题
我正在尝试编写一个Java程序,以监视网站https://www.drpciv.ro/drpciv-booking/formular/23/exchangingForeignDriverLicence上是否有可用的预订位置。
但是当我使用Chrome或Edge查看页面源代码时,正文部分只显示<cbn-root></cbn-root>
。但是使用Chrome的检查功能时,我可以看到完整的正文内容。当我尝试在Java中使用HtmlUnit获取网页内容时,它只获取到<cbn-root></cbn-root>
,没有实际的内容。
尝试过在Google中搜索<cbn-root>
,但没有看到有用的信息。
想知道元素<cbn-root>
是什么,以及如何在这种情况下在Java中读取实际内容。
谢谢
英文:
I was trying to write a Java program to monitor if there are reserved spots becoming available on this website: https://www.drpciv.ro/drpciv-booking/formular/23/exchangingForeignDriverLicence
But when I view page source with Chrome or Edge, the body part show only <cbn-root></cbn-root>
. But using Chrome's Inspect function I can see the complete body. When I try to get the content of the webpage in Java with HtmlUnit it gets only <cbn-root></cbn-root>
and no real content either.
Tried to google <cbn-root>
, but didn't see any useful information.
Wonder what the element <cbn-root> is and how to read the real content in Java in this case.
Thank you
答案1
得分: 0
尝试访问 https://stackoverflow.com/questions/44867425/beautiful-soup-cant-find-tags
它解释了后端 JavaScript 是异步加载的,因此您的 GET 请求实际上无法获取该标签。在此处阅读更多信息。
英文:
Try https://stackoverflow.com/questions/44867425/beautiful-soup-cant-find-tags
It explains that the backend JS is loaded async and your GET request cant acutally get the tag. Read more here.
答案2
得分: 0
public static void main(String[] args) throws IOException {
String url = "https://www.drpciv.ro/drpciv-booking/formular/23/exchangingForeignDriverLicence";
try (final WebClient webClient = new WebClient(BrowserVersion.FIREFOX)) {
webClient.getOptions().setThrowExceptionOnScriptError(false);
HtmlPage page = webClient.getPage(url);
System.out.println(" ---- ");
webClient.waitForBackgroundJavaScript(10_000);
System.out.println(" ---- ");
System.out.println(page.asXml());
}
}
英文:
At least with the upcoming version 2.43.0 the tag gets replaced.
public static void main(String[] args) throws IOException {
String url = "https://www.drpciv.ro/drpciv-booking/formular/23/exchangingForeignDriverLicence";
try (final WebClient webClient = new WebClient(BrowserVersion.FIREFOX)) {
webClient.getOptions().setThrowExceptionOnScriptError(false);
HtmlPage page = webClient.getPage(url);
System.out.println(" ---- ");
webClient.waitForBackgroundJavaScript(10_000);
System.out.println(" ---- ");
System.out.println(page.asXml());
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论