• .NET Framework : 4.7.2
  •        IDE : Visual Studio Community 2019
  •         OS : Windows 10 x64
  •     typesetting : Markdown

乱码 - 示例

code

using System;
using System.Net;

namespace ConsoleApp
{

    class Program
    {
        static void Main(string[] args)
        {
            WebClient webC = new WebClient();
            string webAdress = @"http://www.csn.net/";
            string webContent = webC.DownloadString(webAdress);
            Console.WriteLine(webContent);
            Console.ReadKey();
        }
    }
}

result - 部分

// Traffic Stats of the entire Web site By baidu end
window.csdn.fixedSidebar({
    targetBox: $('nav'), //鍒ゆ柇鍒拌揪搴曢儴鐨勫厓绱?    mainBox: $("main"), //渚ц竟鏍忔梺杈圭殑涓讳綋鍏冪礌
    sidebar: $("nav"), //渚ц竟鏍忎富浣撳厓绱狅紝鍙笌鍒ゆ柇鍒拌揪搴曢儴鐨勫厓绱犵浉鍚?    direction: 'left', //渚ц竟 鏍忔诞鍔ㄦ柟鍚?    position: 'fixed',//瀹氫綅鏂瑰紡
    top:-6,
    bottom: 0,
    zIndex: 99,
    sidebarRightMargin: 13,//direction涓簂eft,渚ц竟鏍忚窛绂籱ainbox鐨勫彸杈硅窛
    sidebarLeftMargin: 15,//direction涓簉ight,渚ц竟鏍忚窛绂籱ainbox鐨勫乏杈硅窛
})

思考与改进

查看网页的字符编码

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">

code

using System;
using System.Net;
using System.Text;

namespace ConsoleApp
{

    class Program
    {
        static void Main(string[] args)
        {
            WebClient webC = new WebClient();
            string webAdress = @"http://www.csn.net/";

            // 注意看这行代码
            webC.Encoding = Encoding.UTF8;

            string webContent = webC.DownloadString(webAdress);
            Console.WriteLine(webContent);
            Console.ReadKey();
        }
    }
}

result - 部分

// Traffic Stats of the entire Web site By baidu end
window.csdn.fixedSidebar({
    targetBox: $('nav'), //判断到达底部的元素
    mainBox: $("main"), //侧边栏旁边的主体元素
    sidebar: $("nav"), //侧边栏主体元素,可与判断到达底部的元素相同
    direction: 'left', //侧边栏浮动方向
    position: 'fixed',//定位方式
    top:-6,
    bottom: 0,
    zIndex: 99,
    sidebarRightMargin: 13,//direction为left,侧边栏距离mainbox的右边距
    sidebarLeftMargin: 15,//direction为right,侧边栏距离mainbox的左边距
})

resource

  • [文档] docs.microsoft.com/zh-cn/dotnet/csharp
  • [规范] github.com/dotnet/docs/tree/master/docs/standard/design-guidelines
  • [源码] referencesource.microsoft.com
  • [ IDE ] visualstudio.microsoft.com/zh-hans
  • [.NET Core] dotnet.github.io


感恩曾经帮助过 心少朴 的人。
C#优秀,值得学习。.NET Core具有跨平台的能力,值得关注。
Console,WinForm,WPF,ASP.NET,Azure WebJob,WCF,Unity3d,UWP可以适当地了解。
注:此文是自学笔记所生,质量中下等,故要三思而后行。新手到此,不可照搬,应先研究其理象数,待能变通之时,自然跳出深坑。

欢迎关注微信公众号:悟为生心

C#基础 WebClient DownloadString 下载网页的源代码_c#