如何获取由javascript设置的网页的隐藏InnerHtml? [英] How to get hidden InnerHtml of web page that set by javascript?

查看:167
本文介绍了如何获取由javascript设置的网页的隐藏InnerHtml?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以使用以下代码获取网页的来源:

I know that I can get source of web page with this code:

browser.DocumentText;

由javascript innetHtml函数填充的页面的某些数据,在browser.Text中不可见,但在browser的输出中可见.

some data of page filled by javascript innetHtml function and will not visible in browser.Text but in browser's output is visible.

如何获取由javascript添加到页面的数据的源代码?

How can I get source code of data that added by javascript to page?

推荐答案

如果您知道哪种类型的标签包含要获取的内部HTML,则可以执行以下操作(此示例循环遍历div标签,但是您可以执行p或表格单元格之类的操作:

If you know what type of tag contains the inner HTML you want to get at, you could do something like this (this example loops through the div tags, but you could do p, or table cells, or whatever):

HtmlElementCollection collection = browser.Document.GetElementsByTagName("div");

foreach (HtmlElement element in collection) {
    string html = element.InnerHtml;
    string text = element.InnerText;
    // do something with the HTML or text here...
}

或者,如果您知道要获取的元素的特定ID,请使用:

Or if you know the specific ID of the element you want to get, use:

HtmlElement element = browser.Document.GetElementById("someId123");
if(null != element) // do something with it...

这篇关于如何获取由javascript设置的网页的隐藏InnerHtml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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