예제 #1
0
        public void MatchEngine(string text, ItemLog log)
        {
            Item item = new Item();

            item.Name   = "";
            item.Price  = 0;
            item.Adress = "";
            int    price = 0;
            string adress;



            /*
             * Item  Name
             *
             */

            string pattern = "<span\\sclass=\"num-icon\\snum-[beds|baths|reception].*?\\stitle=\"(?<data>.*?)\">";

            Regex regixObj = new Regex(pattern, RegexOptions.Singleline | RegexOptions.CultureInvariant);

            foreach (Match i in regixObj.Matches(text))
            {
                Console.WriteLine("Name Found   .... " + i.Groups["data"].Value + "\n\n\n\n");
                item.Name += i.Groups["data"].Value.Replace(",", "-");
            }

            /*
             * Adding Price Here
             *
             */


            pattern  = "class=\"listing-results-price.*?(?<data>&pound;[,|\\d]*).*?</a>";
            regixObj = new Regex(pattern, RegexOptions.Singleline);
            foreach (Match i in regixObj.Matches(text))
            {
                Console.WriteLine("Price Matched   .... " + i.Groups["data"].Value + "\n\n\n\n");
                string temp       = i.Groups["data"].Value.Replace("&pound;", "");
                string tempstring = temp.Replace(",", "");

                int.TryParse(tempstring, out price);
                item.Price = price;
            }



            /*
             * Adding Item Adress
             *
             *
             */
            pattern = "<a itemprop=\"streetAddress\"";
            string AppendingPattern = @".*?>(?<data>.*?)</a>";

            regixObj = new Regex(pattern + AppendingPattern, RegexOptions.Singleline | RegexOptions.CultureInvariant);
            foreach (Match i in regixObj.Matches(text))
            {
                Console.WriteLine("Adress Found   .... " + i.Groups["data"].Value + "\n\n\n\n");
                adress      = i.Groups["data"].Value.Replace(",", "-");
                item.Adress = adress;
            }



            /*Adding Item Company
             *
             */

            pattern = "<img src=\".*?alt=\"(?<data>.*?)\".*?>";

            regixObj = new Regex(pattern, RegexOptions.Singleline | RegexOptions.CultureInvariant);
            foreach (Match i in regixObj.Matches(text))
            {
                Console.WriteLine("Company Matched   .... " + i.Groups["data"].Value + "\n\n\n\n");
                item.Description = i.Groups["data"].Value.Replace(",", "-");
            }



            /*Adding Item Image
             *
             */

            pattern = "<img src=\"(?<data>http://st.zoocdn.com/zoopla_static_agent_logo.*?)\"";

            regixObj = new Regex(pattern, RegexOptions.Singleline | RegexOptions.CultureInvariant);

            foreach (Match i in regixObj.Matches(text))
            {
                Console.WriteLine("Image Matched   .... " + i.Groups["data"].Value + "\n\n\n\n");
                item.Image = i.Groups["data"].Value.Replace(",", "-");
                item.Image.Replace(",", "-");
            }
            log.Add(item);
        }