有高手在吗
   请问在控制台应用程序中怎么读取HTML源码!

解决方案 »

  1.   

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Net;
    using System.IO;namespace ConsoleApplication1
    {
        public class Program
        {
            public static void Main(string[] args)
            {
                Program p=new Program();            Console.Write(p.ljjk(@"http://www.126.com"));
            }
            private string ljjk(string url)
            {
                WebClient webclient = new WebClient();
                Stream st = webclient.OpenRead(url);
                StreamReader sr = new StreamReader(st, System.Text.Encoding.GetEncoding("GB2312"));
                string line;
                string fhz = "";
                while ((line = sr.ReadLine()) != null)
                {
                    fhz += line;
                }
                st.Close();
                sr.Close();
                return fhz;
            }
        }
    }