Exemplo n.º 1
0
        /// <inheritdoc />
        /// <summary>
        /// Method for parse parameters in url.
        /// </summary>
        /// <param name="url">url</param>
        /// <param name="urlElement">xml element for store data</param>
        public override void Parse(string url, XElement urlElement)
        {
            var regex   = new Regex("(\\?|&)(.+?)=(.+?)(&|$)");
            var matches = regex.Matches(url);

            var uriElement = new XElement("parameters");

            foreach (Match match in matches)
            {
                XElement   parametr = new XElement("parametr");
                XAttribute key      = new XAttribute("key", match.Groups[2].Value);
                XAttribute value    = new XAttribute("value", match.Groups[3].Value);
                parametr.Add(key);
                parametr.Add(value);

                uriElement.Add(parametr);
            }

            if (matches.Count != 0)
            {
                urlElement.Add(uriElement);
            }

            NextParser?.Parse(url, urlElement);
        }
Exemplo n.º 2
0
        public void ParseNextProductTest()
        {
            NextParser nextParser = new NextParser();
            string     url        = "http://www.next.co.uk/g92236s7#322425";
            Product    product    = nextParser.ParseNextProduct(url);

            Assert.AreNotEqual(null, product.ThumbnailLink);
        }
Exemplo n.º 3
0
        /// <inheritdoc />
        /// <summary>
        /// Method for parse url.
        /// </summary>
        /// <param name="url">url for parse</param>
        /// <param name="urlElement">xml element to write data</param>
        public override void Parse(string url, XElement urlElement)
        {
            var regex   = new Regex("\\w+:\\/\\/[\\w@][\\w.:@]+\\/?[\\w\\.?=%&=\\-@/$,]*");
            var matches = regex.Matches(url);

            if (matches.Count == 0)
            {
                Exception e = new InvalidUrlException($"{url} - not a url");
                this.Logger.Error(string.Empty, e);
                throw e;
            }

            NextParser?.Parse(url, urlElement);
        }
Exemplo n.º 4
0
        /// <inheritdoc />
        /// <summary>
        /// Method for parse host of url.
        /// </summary>
        /// <param name="url">url</param>
        /// <param name="urlElement">xml element to write data</param>
        public override void Parse(string url, XElement urlElement)
        {
            Regex  regex     = new Regex("://(.+?)/");
            Match  match     = regex.Match(url);
            string hostValue = match.Groups[1].Value;

            XElement   host      = new XElement("host");
            XAttribute attribute = new XAttribute("name", hostValue);

            host.Add(attribute);

            urlElement.Add(host);

            NextParser?.Parse(url, urlElement);
        }
Exemplo n.º 5
0
        public void ParseNextListTest()
        {
            NextParser           nextParser = new NextParser();
            IEnumerable <string> links      = nextParser.ParseNextProductList("https://www.next.co.uk/shop/gender-newborngirls-gender-oldergirls-gender-youngergirls-category-dresses");

            Assert.IsTrue(links.Count() > 650);

            IList <Product> products = new List <Product>();

            foreach (string link in links)
            {
                Console.WriteLine(@"Processing link {0}", link);
                products.Add(nextParser.ParseNextProduct(link));
            }
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            string     url        = "https://www.next.co.uk/shop/gender-newborngirls-gender-oldergirls-gender-youngergirls-category-dresses";
            NextParser nextParser = new NextParser();
            // IEnumerable<string> links = nextParser.ParseNextProductList(url);
            // Utilities.WriteToBinaryFile(@"temp.bin", links);
            IEnumerable <string> links = (Utilities.ReadFromBinaryFile <IEnumerable <string> >(@"temp.bin"));

            Console.WriteLine(@"Total of {0} products found in the page", links.Count());
            IList <Product> products = new List <Product>();

            foreach (string link in links.Take(10))
            {
                Console.WriteLine(@"Processing link {0}", link);
                products.Add(nextParser.ParseNextProduct(link));
            }
        }
Exemplo n.º 7
0
        /// <inheritdoc />
        /// <summary>
        /// Method for parse uri of url.
        /// </summary>
        /// <param name="url">url</param>
        /// <param name="urlElement">xml element for store data</param>
        public override void Parse(string url, XElement urlElement)
        {
            Regex           regex   = new Regex("(?<=[^/]/)([^/]+?)(/|\\?|$)");
            MatchCollection matches = regex.Matches(url);

            XElement uriElement = new XElement("uri");

            foreach (Match match in matches)
            {
                uriElement.Add(new XElement("segment", match.Groups[1].Value));
            }

            if (matches.Count != 0)
            {
                urlElement.Add(uriElement);
            }

            NextParser?.Parse(url, urlElement);
        }
Exemplo n.º 8
0
 public AdminController(IProductRepository repo)
 {
     repository  = repo;
     nextParser  = new NextParser();
     bodenParser = new BodenParser();
 }