在线等:怎么得到网页的源码
在线等:怎么得到网页的源码假设我电脑已经开了一个网页,www.xxx.com,如何得到它的源码? 就是达到和点击浏览器 查看-->源代码 一样的效果就可以了。
一般自己看源代码的时候就是点击 查看、源代码,IE就会弹出一个txt格式的文档。用c#怎么做?怎么把已经打开的ie的源代码取出来?
谢谢 --------------------编程问答-------------------- download string即可。。。 --------------------编程问答-------------------- httpwebrequest
webclient
System.Net.WebClient wc = new System.Net.WebClient();
wc.Credentials = System.Net.CredentialCache.DefaultCredentials;
Byte[] buffer= wc.DownloadData("");
string Content= System.Text.Encoding.Default.GetString(buffer);
--------------------编程问答-------------------- http://leonardleonard.javaeye.com/blog/277073
自己看吧 --------------------编程问答-------------------- http://www.busfly.cn/post/cs-web-WebClient-html.html --------------------编程问答--------------------
try
{
System.Net.WebRequest rqt = System.Net.WebRequest.Create(url);
System.Net.WebResponse rsp = rqt.GetResponse();
System.IO.Stream respStream = rsp.GetResponseStream();
System.IO.StreamReader read = new System.IO.StreamReader(respStream, System.Text.Encoding.GetEncoding("utf-8"));
return read.ReadToEnd();
}
catch (Exception)
{
throw;
}
学人家的。 --------------------编程问答-------------------- 用webbrowser控件吧
webBrowser1.DocumentText --------------------编程问答--------------------
不行,我的网页已经打开在桌面了,只要取得桌面这个打开的网页的源码就可以了 --------------------编程问答-------------------- string html = Encoding.GetEncoding("GB2312").GetString(new WebClient().DownLoadData("网址")); --------------------编程问答--------------------
不行,这个只能到登陆界面的源码,如果有用户名,密码什么的,进不去
我的IE已经打开在桌面,用户名密码登陆进去了,然后IE上有一些数据,这个时候点击IE的 查看--源码 , 是可以看到这些数据的,但是上面的代码不行 --------------------编程问答-------------------- 用这个,高歌一次回帖中提供的方法:
--------------------编程问答--------------------
static class WebFunc
{
private static CookieContainer cookie = new CookieContainer();
private static string contentType = "application/x-www-form-urlencoded";
private static string accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-silverlight, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-silverlight-2-b1, */*";
private static string userAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)";
public static string GetHtmlEx(string url, Encoding encoding)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.UserAgent = userAgent;
request.ContentType = contentType;
request.CookieContainer = cookie;
request.Accept = accept;
request.Method = "get";
WebResponse response = request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream, encoding);
String html = reader.ReadToEnd();
response.Close();
return html;
}
}
//调用
WebFunc.GetHtmlEx("网址",Encoding....)
昏了,不行,读取的还是登陆界面的数据html源码 --------------------编程问答-------------------- 学习了
补充:.NET技术 , C#