如何恢复一个页面的完整HTML,包括是由JavaScript生成的​​内容 [英] How do I recover the full html of a page, including what is generated by javascript

查看:117
本文介绍了如何恢复一个页面的完整HTML,包括是由JavaScript生成的​​内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何恢复页面的完整HTML,包括是由JavaScript生成的​​内容。问题是,我要访问的选择标记的内容,但却页它是未来空的,这可能是被动态生成。请我快要放弃!
我只是贴了一张code,因为这个非常大的,如果我觉得有必要把整个code。

 解析度=(HttpWebResponse)req.GetResponse();
res.Cookies = req.Co​​okieContainer.GetCookies(req.RequestUri);
cookieContainer.Add(res.Cookies);SR =新的StreamReader(res.GetResponseStream());
getHtml = sr.ReadToEnd();
视图状态= rxViewstate.Match(getHtml).Groups [1] .value的;
EventValdidation = rxEventValidation.Match(getHtml).Groups [1] .value的;
视图状态= HttpUtility.UrlEn code(视图状态);
EventValdidation = HttpUtility.UrlEn code(EventValdidation);//这里我应该选择标记的内容。
getHtml = rxDropDownMenu.Match(getHtml).Groups [2]。价值;


解决方案

您不能只是做与的HttpWebRequest ,所有做的是下载的原始HTML和非的链接JavaScript文件。

这也不会运行JavaScript或给你任何种类的DOM检查。

您会真正需要使用 web浏览器或者像 Awesomium

How do I recover the full html of a page, including what is generated by javascript. The problem is that I want to access the contents of the select tag, but the page but it is coming empty, this probably being generated dynamically. Please I'm about to give up! I just posted a piece of code because this very large, if I find it necessary to put the whole code.

res = (HttpWebResponse)req.GetResponse();
res.Cookies = req.CookieContainer.GetCookies(req.RequestUri);
cookieContainer.Add(res.Cookies);

sr = new StreamReader(res.GetResponseStream());
getHtml = sr.ReadToEnd();
viewstate = rxViewstate.Match(getHtml).Groups[1].Value;
EventValdidation = rxEventValidation.Match(getHtml).Groups[1].Value;
viewstate = HttpUtility.UrlEncode(viewstate);
EventValdidation = HttpUtility.UrlEncode(EventValdidation);

//Here I should take the contents of the select tag.
getHtml = rxDropDownMenu.Match(getHtml).Groups[2].Value;

解决方案

You can't just do this with HttpWebRequest, all that does is download the raw HTML and non of the linked JavaScript files.

It also wouldn't run the JavaScript or give you any kind of DOM to inspect.

You'd really need to use WebBrowser or perhaps something like Awesomium.

这篇关于如何恢复一个页面的完整HTML,包括是由JavaScript生成的​​内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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