获取浏览器的内容?
winform,获取webbroswer的内容
System.IO.StreamReader getReader = new System.IO.StreamReader(this.webBrowser1.DocumentStream, System.Text.Encoding.GetEncoding("utf-8"));
string gethtml = getReader.ReadToEnd();
提示内容不能为null
------解决方案--------------------http://zhidao.baidu.com/question/89819897.html
如果只获取html代码用不着webbrowser
public string GetHtml(string url, Encoding ec)
{
try
{
WebRequest request = WebRequest.Create(url);//实例化WebRequest对象
WebResponse response = request.GetResponse();//创建WebResponse对象
Stream datastream = response.GetResponseStream();//创建流对象
StreamReader reader = new StreamReader(datastream, ec);
string str = reader.ReadToEnd();
response.Close();
reader.Close();
datastream.Close();
return str;//读取数据
}
catch (Exception e)
{ return ""; }
}