使用Java执行页面上的Javascript后,如何访问更新的HTML源代码? [英] How to access updated HTML source after the Javascript on the page has been executed, in Java?

查看:64
本文介绍了使用Java执行页面上的Javascript后,如何访问更新的HTML源代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Java中的Jsoup从网页中获取元素及其各自的属性.但是,我已经意识到,在页面加载后会有一些javascript运行,从而创建了一个表,该表包含了我要在页面上访问的所有信息.

I am trying to grab elements and their respective attributes from a webpage using Jsoup in java. However, I've realized that there is some javascript that runs after the page has been loaded that creates a table, which holds all of the information I am trying to access on the page.

使用Java,我想知道在执行javascript之后是否有任何方法可以访问更新的HTML源代码,以便可以获取所需表中的元素.

Using java, I was wondering if there is any way to access the updated HTML source after the javascript has executed so that I can grab the elements in the table that I need.

谢谢.

推荐答案

jsoup不支持javascript执行,您必须使用其他方法来加载页面,获取源代码,然后将其传递给jsoup来解析您想要的信息.

jsoup doesn't support javascript execution, you'll have to use something else to load the page, grab the source and then pass it to jsoup to parse the info you want.

在这种情况下我使用了几个库:

A couple libraries I have used in this situation:

  • selenium
  • ui4j

还有其他一些,但是这是我使用过的两个,建议您放心使用.

There are others but these are the two I have used and feel comfortable recommending.

糟糕,只是做了一些谷歌搜索,看来这是一个非常相似的问题

Oops, just did some Googling, seems this is a very similar question

此外,请参见无头浏览器列表.很好的答案,我已将此标签加为书签.

Also, see this list of headless browsers. Great answer, I have this one bookmarked.

这篇关于使用Java执行页面上的Javascript后,如何访问更新的HTML源代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆