如何解析通过Java脚本生成的HTML代码 [英] How do I parse an HTML Code which is generated via Java Script

查看:156
本文介绍了如何解析通过Java脚本生成的HTML代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的任务是通过vba下载文件。问题是,该页面大部分是通过JavaScript生成的。对不起,我不能只与你分享网页,因为我没有拥有它,但我会尽量让事情变得尽可能清晰。

来自IE源代码的HTML查看器看起来类似于此:

 < head> 
css东西
jscript链接
更多jscript链接
更多css东西
< / head>
< body>
divs和链接等等


< / body>

我非常相信java脚本会生成一个iframe并用html代码填充它。

你认为可以从java脚本中检索完成的iframe吗?因为当我使用chrome DOM浏览器时,我可以从字面上看到HTML代码,但我无法在vba中获取HMTL数据。这让我疯狂,我不明白这一点:D



感谢您的时间

解决方案

您所描述的内容看起来像一个典型的DHTML,可以在XHR请求之后由JS生成。所以打开网页e。 G。在Chrome中,选中网络标签。在页面上生成目标内容后,您将看到选项卡上的所有请求,检查它们,通常所有需要检索的数据都显示在那里(请注意,可能需要对数据进行一些转换)。如果你找到它,那么你可以用相同的参数做一个XHR来检索结果。换句话说,如果iframe与上面提到的相同,则可以检索生成的访问DOM的HTML内容。


My task at hand is to download a file through vba. The problem is, that the page is mostly generated via JavaScript. Sorry that i cannot just share the page with you, because I dont own it, but I will try to make things as clear as possible.

The HTML from the IE source viewer looks similar to this:

<head>
  css stuff
  jscript link
  more jscript links
  more css stuff
</head>
<body>
divs and links and so on

<div magic inside that div that shows on browser but not in source code></div>

</body>

I very much believe that the java script generates an iframe and fills it with html code.

Do you think that it is possible to retrieve the finished iframe from the java script? Because I can literally see the HTML code when i use the chrome DOM explorer, but I cannot fetch the HMTL data in vba. It drives me crazy that I dont understand this :D

Thank you for your time

解决方案

What you have described looks like a typical DHTML that could be generated by JS after XHR request. So open the web page e. g. in Chrome, check the Network tab. After the target content has been generated on the page, you will see all requests on the tab, examine them, usually all the data you need to retrieve are shown there (note that some conversion of the data may be necessary).  If you find it then you may just do a XHR with the same parameters to retrieve result. Or another way, you can retrieve the generated HTML content accessing DOM, if the iframe is same origin, as it was mentioned above.

这篇关于如何解析通过Java脚本生成的HTML代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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