获取网页的html代码
<span style="font-family: Arial, Helvetica, sans-serif;">NSoup.Nodes.Document doc = NSoup.NSoupClient.Connect("http://blog.csdn.net/dingxiaowie2013").Get();</span>
NSoup.Nodes.Document doc = NSoup.NSoupClient.Parse(HtmlString);
但是很遗憾NSoup默认的是UTF-8,处理中文会有乱码(对于编码是UTF-8自然会正常,但是有些是GB2312的就可能有乱码)
//下载网页源代码
WebClient webClient = new WebClient();
string htmlString = Encoding.GetEncoding("utf-8").GetString(webClient.DownloadData("http://www.baidu.com"));
NSoup.Nodes.Document doc = NSoup.NSoupClient.Parse(htmlString);
2.获得网页的流
//获得网页流
WebRequest webRequest = WebRequest.Create("http://blog.csdn.net/dingxiaowei2013");
NSoup.Nodes.Document doc1 = NSoup.NSoupClient.Parse(webRequest.GetResponse().GetResponseStream(), "utf-8");
效果图
==================== 迂者 丁小未 CSDN博客专栏=================
MyBlog:http://blog.csdn.net/dingxiaowei2013 MyQQ:1213250243
Unity QQ群:375151422,858550,6348968 cocos2dx QQ群:280818155
====================== 相互学习,共同进步 ===================