public void ScrapeHtml(string path)
        {
            JsonContent = "NO CONTENT";
            var    addLine             = false;
            string getLastHtmlFullName = CinevoFiles.GetLastHtmlPath(path);

            if (getLastHtmlFullName != null && !getLastHtmlFullName.Equals(string.Empty))
            {
                Cinemas = new List <Cinema>();
                var linesPerCinema = new ArrayList();
                var fileReader     = new StreamReader(getLastHtmlFullName);

                string line;
                var    counter     = 0;
                var    cinemaAdded = 2;

                while ((line = fileReader.ReadLine()) != null)
                {
                    if (line.Contains("<!-- /listado CINES -->"))
                    {
                        break;
                    }

                    if (!line.Trim().Equals(string.Empty) && line.Trim().Length > 20)
                    {
                        if (line.Contains("col-xs-12 col-sm-6 col-md-6 info-cine"))
                        {
                            addLine = true;
                            counter++;
                        }

                        if (addLine)
                        {
                            if (counter - cinemaAdded == 0)
                            {
                                Cinema cinema = ConvertToObject(linesPerCinema);
                                if (cinema.Name != null)
                                {
                                    Cinemas.Add(cinema);
                                }
                                counter     = 0;
                                cinemaAdded = 1;
                                linesPerCinema.Clear();
                                linesPerCinema.Add(line);
                            }
                            else
                            {
                                linesPerCinema.Add(line);
                            }
                        }
                    }
                }

                fileReader.Close();
                fileReader.Dispose();
                JsonContent = JsonConvert.SerializeObject(Cinemas).Trim().TrimEnd().TrimStart();
            }
        }
Exemple #2
0
        public void ScrapeHtml(string path)
        {
            JsonContent = "NO CONTENT";
            var    addLine             = false;
            string getLastHtmlFullName = CinevoFiles.GetLastHtmlPath(path);

            if (getLastHtmlFullName != null && !getLastHtmlFullName.Equals(string.Empty))
            {
                Towns = new List <Town>();
                var fileReader = new StreamReader(getLastHtmlFullName);

                string line;
                while ((line = fileReader.ReadLine()) != null)
                {
                    if (line.Contains("</select>"))
                    {
                        break;
                    }

                    if (line.Contains("id=\"dropdown-listado-poblacion\" class=\"form-control\""))
                    {
                        addLine = true;
                    }

                    if (addLine)
                    {
                        if (line.Contains("data-name"))
                        {
                            Towns.Add(ConvertToObject(line));
                        }
                    }
                }

                fileReader.Close();
                fileReader.Dispose();
            }
            JsonContent = JsonConvert.SerializeObject(Towns).Trim().TrimEnd().TrimStart();
            Console.WriteLine("CINEVO TOWN SCRAPPER: JsconContent added...");
        }