How to get hidden InnerHtml of web page that set by javascript?

做~自己de王妃 提交于 2019-12-11 04:42:00

问题


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

browser.DocumentText;

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

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


回答1:


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...
}

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...



回答2:


You could give HtmlAgilityPack a try and follow this answer.

HtmlWeb webGet = new HtmlWeb();
HtmlAgilityPack.HtmlDocument doc = webGet.Load(url);


来源:https://stackoverflow.com/questions/17094136/how-to-get-hidden-innerhtml-of-web-page-that-set-by-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!