Пример #1
0
        //解析大型水库
        public void ParseBigReservoir()
        {
            int count = 0;
            HtmlNodeCollection anchors = this.bigReservoirDoc.DocumentNode.SelectNodes(@"/table/tr");

            foreach (HtmlNode hn in anchors)
            {
                ReservoirHydrology rh = new ReservoirHydrology();
                //解析流域
                HtmlNode nodeBasin = hn.SelectNodes("td").FindFirst("td");
                string   basin     = UnicodeToString(nodeBasin.InnerText.Trim());
                rh.Basin = basin;

                //解析行政区
                HtmlNode nodeDistruct = hn.SelectNodes("td[2]").FindFirst("td");
                string   distruct     = UnicodeToString(nodeDistruct.InnerText.Trim());
                rh.AdministrativeRegion = distruct;

                //解析河名
                HtmlNode nodeRiver = hn.SelectNodes("td[3]").FindFirst("td");
                rh.RiverName = UnicodeToString(nodeRiver.InnerText.Trim());

                //解析站名
                HtmlNode nodeStation = hn.SelectNodes("td[4]/font").FindFirst("font");
                rh.StationName = UnicodeToString(nodeStation.InnerText.Trim());

                //解析时间
                rh.Time = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);

                //解析库水位
                HtmlNode nodeLevel      = hn.SelectNodes("td[5]/font").FindFirst("font");
                char[]   delimiterChars = { '\\' };
                string[] words          = nodeLevel.InnerText.Trim().Split(delimiterChars);
                try
                {
                    rh.WaterLevel = Convert.ToDouble(words[0].Trim());
                }
                catch (Exception)
                {
                    rh.WaterLevel = -1.0;
                }

                //解析蓄水量
                HtmlNode nodeFlow = hn.SelectNodes("td[6]").FindFirst("td");
                try
                {
                    rh.Pondage = Convert.ToDouble(nodeFlow.InnerText.Trim());
                }
                catch (Exception)
                {
                    rh.Pondage = -1.0;
                }

                //解析警戒水位

                /*HtmlNode nodeWarning = hn.SelectNodes("td[8]").FindFirst("td");
                 * try
                 * {
                 *  rh.WarningWaterLevel = Convert.ToDouble(nodeWarning.InnerText.Replace("&nbsp", "").Trim());
                 * }
                 * catch (Exception)
                 * {
                 *  rh.WarningWaterLevel = -1.0;
                 * }*/
                rh.WarningWaterLevel = -1.0;
                listBigReservoir.Add(rh);
                count++;
            }
            LogHelper.WriteLog(typeof(HtmlParse), "大型水库水情数据爬取解析成功,共:" + count + "条");
        }
Пример #2
0
        //解析全国重点水库站实时水情
        public void ParseReservoirHydrology()
        {
            int count = 0;
            HtmlNodeCollection anchors = this.reservoirDoc.DocumentNode.SelectNodes(@"/table/tr");

            foreach (HtmlNode hn in anchors)
            {
                ReservoirHydrology rh = new ReservoirHydrology();

                //解析站名
                HtmlNode nodeStationName = hn.SelectNodes("td/a/font").FindFirst("font");
                rh.StationName = UnicodeToString(nodeStationName.InnerText.Trim());

                //解析站址
                HtmlNode nodeAddress = hn.SelectNodes("td[2]").FindFirst("td");
                rh.StationAddress = UnicodeToString(nodeAddress.InnerText.Trim());

                //解析河名
                HtmlNode nodeRiverName = hn.SelectNodes("td[3]").FindFirst("td");
                rh.RiverName = UnicodeToString(nodeRiverName.InnerText.Trim());

                //解析库水位
                HtmlNode nodeLevel = hn.SelectNodes("td[4]/font").FindFirst("font");
                try
                {
                    rh.WaterLevel = Convert.ToDouble(nodeLevel.InnerText.Trim());
                }
                catch (Exception)
                {
                    rh.WaterLevel = -1.0;
                }

                //解析蓄水量
                HtmlNode nodePondage = hn.SelectNodes("td[5]").FindFirst("td");
                try
                {
                    rh.Pondage = Convert.ToDouble(nodePondage.InnerText.Trim());
                }
                catch (Exception)
                {
                    rh.Pondage = -1.0;
                }

                //解析时间
                HtmlNode nodeTime = hn.SelectNodes("td[6]").FindFirst("td");
                string   timeStr  = nodeTime.InnerText.Trim();
                rh.Time = StrToTime(timeStr);

                //解析汛限水位
                HtmlNode nodeWarning = hn.SelectNodes("td[7]").FindFirst("td");
                try
                {
                    rh.WarningWaterLevel = Convert.ToDouble(nodeWarning.InnerText.Replace("&nbsp", "").Trim());
                }
                catch (Exception)
                {
                    rh.WarningWaterLevel = -1.0;
                }

                listReservoir.Add(rh);
                count++;
            }

            LogHelper.WriteLog(typeof(HtmlParse), "重点水情数据爬取解析成功,水库站:" + count + "条");
        }