JavaScript 操作后获取 HTML 源代码 [英] Get HTML Source after JavaScript manipulations

查看:30
本文介绍了JavaScript 操作后获取 HTML 源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何得到完整的!网页的 HTML 源代码,在它运行了一些对 HTML 源代码进行操作的 JavaScript 代码之后.

How do i get the full! HTML source of a web page, after it has run some JavaScript code which has made manipulations to the HTML source.

我正在使用 VB.Net 的 WebbrowserControl,我想为我的自定义 webbrowsercontrol 创建一个额外的功能,它接收完整的 HTML 源.

I'm using the WebbrowserControl of VB.Net, i'd like to create an extra function of my custom webbrowsercontrol which receives the full HTML source.

提前致谢

推荐答案

诀窍是找到一种方法来通知控件有关 JS 是否已完成运行.您可以通过让 JS 在完成时设置表单元素的值 (isJSComplete) 并使用 Web 浏览器控件进行轮询来做到这一点.

The trick is going to be finding a way to notify the control about whether the JS is done running. You might be able to do that by having the JS set a form element' value (isJSComplete) when it has completed and polling with the web browser control.

使用下面的代码检查一个表单值,看它是否准备好了

MyBrowserControl.document.getElementById('isJSComplete');

使用以下代码从页面中提取 HTML.

MyBrowserControl.Document.documentElement.OuterHTML

更好的是,这是一篇文章,展示了如何连接要由 WebBrowser 控件处理的 JS 事件.您可以在 JS 完成后触发一个事件,并让您的代码捕获该事件,然后使用上述方法提取 HTML.

Better yet, here is an article showing how to wire up JS events to be handled by the WebBrowser control. You could just fire an event when the JS is done and have your code trap that event and then pull the HTML using the above approach.

这篇关于JavaScript 操作后获取 HTML 源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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