如何获得某个网页的当前HTML代码(非源代码) 如何获得某个网页的当前HTML代码(非源代码)是当前html代码 而不是源代码因为html页面加载后,可能通过javascript修改过一些东西,所以与源代码不同,再次说明下,我是想得到当前的html代码 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 通过Google浏览器可以的,或者使用Webbrowser结合 JS,应该可以的 我是想把里面的http代码引用到程序里 HttpWebRequest webRequest; CookieCollection mycookie = new CookieCollection(); CookieContainer cookies = new CookieContainer(); /// <summary> /// 获取页面源文件 /// </summary> /// <param name="url"></param> /// <returns></returns> public string getUrl(string url) { try { webRequest = (HttpWebRequest)WebRequest.Create(new Uri(url)); webRequest.CookieContainer = new CookieContainer(); webRequest.CookieContainer.Add(mycookie); webRequest.Method = "GET"; webRequest.Timeout = 10000;//连接时间10秒超时 webRequest.ContentType = "application/x-www-form-urlencoded"; webRequest.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/x-shockwave-flash, */*"; webRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; EmbeddedWB 14.52 from: http://www.baidu.com/ EmbeddedWB 14.52; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"; HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse(); mycookie.Add(response.Cookies); cookies.Add(mycookie); StreamReader sr2 = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(response.CharacterSet)); string text2 = sr2.ReadToEnd(); return text2; } catch (System.Exception ex) { return ""; } } webbrowser 好多属性,可以说具体点吗?不知道是我没有说清楚还是都是瞎混分的,貌似只有小贝明白我的意思.(我感觉我说的很清楚了,强调了N遍,我不是要源代码) 你试过没有啊..这那个就是获取当前页面html代码的~~你把当前页面的地址传进去返回出来的就是当前html~~~ webBrowser用法:IHTMLWindow2 login = (mshtml.IHTMLWindow2)webBrowser1.Document.Window.DomWindow;login 这个也是当前html下面是执行里面的js:login.execScript("js", "javascript"); 在html中点击右键,菜单里的 查看源文件 WPF中使用DatePicker要求值显示月份不显示日期!怎么实现? C# System.AddIn 插件体系中 如何让主机程序响应插件中触发的事件 如何给自定义控件设置默认取消按钮和默认回车按钮? 请教如何实现"在一串字符中至少有一个是中文字符"的regex 时钟是怎么终止? 在.net平台中如何访问数据库 winform里怎样让文字纵向显示? 给asp:Button加上背景 问下,在网上下载了个程序,带源码的?怎么修改URl和image的路径会报错是怎么回事呢 急,菜鸟问题,在一个文本框里怎么限制字符输入 请教高手设计关系表 求助:对各字节做"异或"运算是怎么回事?
CookieCollection mycookie = new CookieCollection();
CookieContainer cookies = new CookieContainer(); /// <summary>
/// 获取页面源文件
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
public string getUrl(string url)
{
try
{
webRequest = (HttpWebRequest)WebRequest.Create(new Uri(url));
webRequest.CookieContainer = new CookieContainer();
webRequest.CookieContainer.Add(mycookie);
webRequest.Method = "GET";
webRequest.Timeout = 10000;//连接时间10秒超时
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/x-shockwave-flash, */*";
webRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; EmbeddedWB 14.52 from: http://www.baidu.com/ EmbeddedWB 14.52; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
mycookie.Add(response.Cookies);
cookies.Add(mycookie);
StreamReader sr2 = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(response.CharacterSet));
string text2 = sr2.ReadToEnd();
return text2;
}
catch (System.Exception ex)
{
return "";
}
}
(我感觉我说的很清楚了,强调了N遍,我不是要源代码)
这那个就是获取当前页面html代码的~~
你把当前页面的地址传进去返回出来的就是当前html~~~