Пример #1
0
        protected WeatherDataDto Fetch(HtmlDocument htmlDocument, ParseInfo parseInfo)
        {
            var cloudy = GetXPath(htmlDocument, "Облачность", "/td[{0}]/div[1]/div".F(parseInfo.TimeOfDay));

            // In one time of day two description
            var description = GetXPath(htmlDocument, "Явления погоды", "/td[{0}]/div[1]".F(parseInfo.TimeOfDay * 2 - 2));
            var isFog = "//*[@id='forecastTable']/tr[5]/td[{0}]/div[1]".F(parseInfo.TimeOfDay - 1);
            var airTemp = GetXPath(htmlDocument, "Температура", "/td[{0}]/div[1]/b".F(parseInfo.TimeOfDay));
            var realFeel = GetXPath(htmlDocument, "Ощущается", "/td[{0}]/div[1]".F(parseInfo.TimeOfDay));
            var sameRealFeel = GetXPath(htmlDocument, "Ощущается", "/td[{0}]".F(parseInfo.TimeOfDay));
            var pressure = "//*[@id='forecastTable']/tr[last()-7]/td[{0}]/div[1]/b|//*[@id='forecastTable']/tr[last()-7]/td[{0}]/div[1]".F(parseInfo.TimeOfDay);
            var windDirection = "//*[@id='forecastTable']/tr[last()-4]/td[{0}]".F(parseInfo.TimeOfDay);
            var windSpeed = GetAvailablePath(htmlDocument,
                "//*[@id='forecastTable']/tr[last()-6]/td[{0}]/div[1]".F(parseInfo.TimeOfDay),
                "//*[@id='forecastTable']/tr[last()-6]/td[{0}]".F(parseInfo.TimeOfDay));
            var humidity = "//*[@id='forecastTable']/tr[last()-3]/td[{0}]".F(parseInfo.TimeOfDay);
            var date = "//*[@id='forecastTable']/tr[1]/td[{0}]/div/div/span[2]".F(parseInfo.Day);

            return new WeatherDataDto
            {
                Provider = Provider.Rp5,
                ProviderName = "Rp5",
                DateTime = this.GetDateInTable(htmlDocument.GetInnerText(date), parseInfo.TimeOfDayKey),
                Cloudy = this.ConvertCloudy(htmlDocument.GetAttribute(cloudy, "onmouseover")),
                Precipitation = this.ConvertPrecipitation(htmlDocument.GetAttribute(description, "onmouseover")),
                StrengthPrecipitation = this.ConvertStrengthPrecipitation(htmlDocument.GetAttribute(description, "onmouseover")),
                IsFog = this.ConvertFog(htmlDocument.IsAttribute(isFog, "onmouseover") ? htmlDocument.GetAttribute(isFog, "onmouseover") : string.Empty),
                IsThunderstorm = this.ConvertThunderstorm(htmlDocument.GetAttribute(description, "onmouseover")),
                AirTemp = Int32.Parse(htmlDocument.GetInnerText(airTemp)),
                RealFeel = this.ConvertRealFeel(htmlDocument, sameRealFeel, airTemp, realFeel),
                Pressure = Double.Parse(htmlDocument.GetInnerText(pressure)),
                WindDirection = this.ConvertWindDirection(htmlDocument.GetInnerText(windDirection)),
                WindSpeed = Double.Parse(htmlDocument.GetInnerText(windSpeed)),
                Humidity = Double.Parse(htmlDocument.GetInnerText(humidity))
            };
        }
Пример #2
0
        private bool IsSameRealFeel(HtmlDocument htmlDocument, string sameRealFeelXPath)
        {
            var isSameRealFeel = htmlDocument.IsAttribute(sameRealFeelXPath, "onmouseover");

            return isSameRealFeel && IsMatch(htmlDocument.GetAttribute(sameRealFeelXPath, "onmouseover"), "равно значению температуры воздуха");
        }