Пример #1
0
        public List <BusStopDescription> LoadLinesId()
        {
            using (var response = new HttpClient().GetAsync($"{url}/pg_FindLines.php").Result)
            {
                if (response.IsSuccessStatusCode)
                {
                    docPage.LoadHtml(response.Content.ReadAsStringAsync().Result);
                }
            }

            var linhas = new List <BusStopDescription>();

            docPage.DocumentNode.SelectNodes("//*[@id='middle']/a").ToList().ForEach(node =>
            {
                var linha          = new BusStopDescription();
                var linhaCodigo    = node.SelectNodes(".//span/strong")?.First()?.InnerText.Split(' ')[1];
                var linhaDescricao = node.SelectNodes(".//span[2]")?.First()?.InnerText;
                var link           = node.Attributes["href"].Value;

                Uri myUri      = new Uri($"{url}/{link}");
                string idLinha = HttpUtility.ParseQueryString(myUri.Query).Get("idLinha");

                linha.Code        = linhaCodigo;
                linha.LineId      = idLinha;
                linha.Description = linhaDescricao.Length > 70 ?
                                    linhaDescricao.Substring(0, 70) : linhaDescricao;
                linha.FullDescription = linhaDescricao;


                linhas.Add(linha);
            });

            return(linhas);
        }
Пример #2
0
        static void ConsultaLinhas()
        {
            HtmlWeb webPage = new HtmlWeb();
            var     url     = "https://quantotempofaltapg.piracicabana.com.br";

            var doc = webPage.Load(url + "/pg_FindLines.php");

            var linhas = new List <BusStopDescription>();

            doc.DocumentNode.SelectNodes("//*[@id='middle']/a").ToList().ForEach(node =>
            {
                var linha          = new BusStopDescription();
                var linhaCodigo    = node.SelectNodes(".//span/strong")?.First()?.InnerText.Split(' ')[1];
                var linhaDescricao = node.SelectNodes(".//span[2]")?.First()?.InnerText;
                var link           = node.Attributes["href"].Value;

                Uri myUri      = new Uri($"{url}/{link}");
                string idLinha = HttpUtility.ParseQueryString(myUri.Query).Get("idLinha");

                linha.Code        = linhaCodigo;
                linha.LineId      = idLinha;
                linha.Description = linhaDescricao.Length > 70 ?
                                    linhaDescricao.Substring(0, 70) : linhaDescricao;


                linhas.Add(linha);
            });
        }