获取源代码

 WebRequest webRequest = WebRequest.Create(_url);
            HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
            StreamReader streamReader = new StreamReader(webResponse.GetResponseStream(), System.Text.Encoding.GetEncoding("gb2312"));

            string[] citys = _citys.Split(new char[] { ',' });//得到数组
            //string DeleteData = "delete [GSEGC_AD]..[Weather]";
            //IUDData(DeleteData);
            string sLine = "";

            while (sLine != null)
            {
                sLine = streamReader.ReadLine();
                for (int i = 1; i<citys.Length; i++)
                {
                    if (sLine != null && sLine.StartsWith("new Array(\"" + i.ToString() + "\",\"" + citys[i] + "\""))
                    {
                        Console.WriteLine(i + " " + citys[i]);

                        string delimStr = ",";
                        string delim = "\"";

                        sLine = sLine.Substring(sLine.IndexOf("(") + 1, sLine.LastIndexOf(")") - sLine.IndexOf("(") - 1);
                        string[] weatherInfo = sLine.Split(delimStr.ToCharArray());
                        city = weatherInfo[1].Trim(delim.ToCharArray());//城市名称
                        today = weatherInfo[2].Trim(delim.ToCharArray());
                        today_weather = weatherInfo[3].Trim(delim.ToCharArray());
                        today_ltemp = weatherInfo[4].Trim(delim.ToCharArray());
                        today_htemp = weatherInfo[5].Trim(delim.ToCharArray());
                        today_pic = weatherInfo[6].Replace("\\", "").Trim(delim.ToCharArray());

你可能感兴趣的:(源代码)