Exemple #1
0
    private void Page_Load(object sender, System.EventArgs e)
    {
        cnString = ConfigurationSettings.AppSettings["connectionstring"].ToString();
            Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);

            /* List<string> list1 = new List<string>();
             string ll = getHours("trtd16:00,1:00/td td width=\"20\"/tdtd class=\"w2b\"â/td/trtrtd20:30/td td width=\"20\"/tdtd class=\"w2b\"ã/td/trtrtd/td td width=\"20\"/tdtd class=\"w2b\"/td/tr".Replace(">", "").Replace("<", ""),
                 list1);
             Response.Write("Count:" + list1.Count+" ");
             ll = getHours(ll, list1);
             Response.Write("Count:" + list1.Count + " ");
             List<string> list2 = new List<string>();
             ll = getHours(ll, list2);
             Response.Write("Count:" + list2.Count + " ");
             return;
             */
            string page = readPage1("http://movies.walla.co.il");
            //string filterArr[] = page.Split('dropdown_selection'); // all code before dropdown_selection is unneeded
            string[] pageLines = page.Split('\n');
            DbControl dbControl = new DbControl();
            foreach (string line in pageLines)
            {
                string strToFind = "onclick=\"location.href='/movie/";
                int index = line.IndexOf(strToFind);
                string movieId;
                if (index > 0)
                {
                    movieId = line.Substring(index + strToFind.Length, 4);
                    Match movieIdMatch = Regex.Match(movieId, "[0-9]*", RegexOptions.IgnoreCase);
                    movieId = movieIdMatch.Value;

                    string movieUrl = line.Substring(line.IndexOf(strToFind) + strToFind.Length);
                    movieUrl = movieUrl.Substring(0, movieUrl.IndexOf("';"));
                    string moviePage = readPage1("http://movies.walla.co.il/movie/" + movieUrl);
                    string hebrewName = getStringInBetween(moviePage, "class=\"right block\">", "</span>");
                    string englishName = getStringInBetween(moviePage, "class=\"left block\">", "</span>");

                    if (dbControl.hasMovie(movieId) == true)
                        continue;

                    Response.Write("<BR>" + "movie:" + movieId + "<BR>");
                    Match imageMatch = Regex.Match(line, "http://msc.wcdn.co.il/archive/[0-9-]*.jpg", RegexOptions.IgnoreCase);
                    string movieIcon = "";
                    if (imageMatch.Success)
                    {
                        movieIcon = imageMatch.Value;
                        Response.Write(movieIcon + "<BR>");
                    }
                    dbControl.addMovie(movieId, hebrewName, englishName, movieIcon);

                    string findCinemasUrl = @"http://movies.walla.co.il/?w=/@ajax.movie.projections&movie_id=" + movieId;
                    //http://movies.walla.co.il/?w=/@ajax.movie.projection.time&movie_id=4673&cinema_id=38
                    string cinemasPage = readPage1(findCinemasUrl);
                    string[] cinemasPageLines = cinemasPage.Split('\n');
                    List<string> cinemasList = new List<string>();
                    List<string> cinemasIdList = new List<string>();

                    foreach (string cinemasLine in cinemasPageLines)
                    {
                        string cinemasLineStrip = cinemasLine.ToLower();
                        strToFind = "\"w3b\"";
                        int indexStart = cinemasLineStrip.IndexOf(strToFind);
                        int indexEnd = cinemasLineStrip.IndexOf("</a>");
                        string cinemaLineSuf;
                        if (indexEnd > 0)
                        {
                            cinemaLineSuf = cinemasLineStrip.Substring(indexStart + strToFind.Length, indexEnd - (indexStart + strToFind.Length));
                            //MatchCollection matches = Regex.Matches("[a-zA-Z0-9]*", cinemasLineStrip, RegexOptions.IgnoreCase);
                            MatchCollection matches = Regex.Matches(cinemaLineSuf, "[a-zà-ú\\- ]*", RegexOptions.IgnoreCase);
                            if (indexStart > 0 && indexEnd > 0)
                            {
                                foreach (Match match1 in matches)
                                {
                                    string cinema = match1.Value;
                                    if (cinema.Length > 1)
                                    {
                                        cinemasList.Add(cinema);
                                        Response.Write(cinema);
                                    }
                                }
                            }
                        }
                        strToFind = "/?w=/";
                        indexStart = cinemasLineStrip.IndexOf(strToFind);
                        indexEnd = cinemasLineStrip.IndexOf("/@cinema");
                        if (indexStart > 0 && indexEnd > 0)
                        {
                            string cinemaId = cinemasLineStrip.Substring(indexStart + strToFind.Length, indexEnd - (indexStart + strToFind.Length));
                            cinemasIdList.Add(cinemaId);
                            Response.Write(cinemaId + "<BR>");

                            string timesPage = readPage1(@"http://movies.walla.co.il/?w=/@ajax.movie.projection.time&movie_id=" + movieId + "&cinema_id=" + cinemaId);
                            //Response.Write(timesPage+"<BR>");
                            string[] timesPageLines = timesPage.Split(new string[] { "</tr>" }, StringSplitOptions.RemoveEmptyEntries);
                            List<DateTime> dates = new List<DateTime>();
                            foreach (string timesLine in timesPageLines)
                            {

                                if (timesLine.Replace("<BR>", "").Replace(">", "").Replace("<", "").Replace(" ", "").Length < 4)
                                    continue;
                                GetTimesAndDays(timesLine, dates);
                            }
                            if (dates != null && dates.Count > 0)
                                dbControl.addMovieTimes(Int32.Parse(movieId), dates, Int32.Parse(cinemaId));
                        }
                    }
                }
                strToFind = "</span>";
                index = line.IndexOf(strToFind);
                Match match = Regex.Match(line, "[à-ú]");
                if (line.Replace("\t", "").Replace(" ", "").StartsWith(strToFind) && match.Success && index > 0 && line.Length > index + strToFind.Length)
                {
                    string name = line.Substring(index + strToFind.Length, line.Length - (index + strToFind.Length));
                    //	Response.Write(name + "<BR>");
                    //	Response.Write("found: " + line.Replace("<","") + "<br>");
                }

            }
    }