Exemplo n.º 1
0
        public List <Ad> ParseHomePage(HtmlDocument doc, ScanPageDto scanPage)
        {
            List <Ad>          adsList = new List <Ad>();
            HtmlNodeCollection docs    = doc.DocumentNode.SelectNodes("//div[@class='container']");

            foreach (HtmlNode ad in docs)
            {
                HtmlNode nod = ad.SelectSingleNode("div[@class='title']/a");

                string title = nod.InnerText.Trim();
                string url   = scanPage.HostUrl + nod.Attributes["href"].Value;
                string idAds = url.Split('/').Last();

                HtmlNode priceTemp =
                    ad.SelectSingleNode(
                        "div[@class='info']/div[@class='price']/span[@class='value']/span[@class='amount']");
                decimal price = ScrapExtensions.ConvertStringToDecimal(priceTemp?.InnerText);

                Ad ads = Ad.Create(Guid.NewGuid(), idAds, title, url, price, scanPage.Host, scanPage.HostUrl);

                adsList.Add(ads);
            }

            return(adsList);
        }
Exemplo n.º 2
0
        public List <Ad> ParseHomePage(HtmlDocument doc, ScanPageDto scanPage)
        {
            List <Ad>          adsList = new List <Ad>();
            HtmlNodeCollection docs    = doc.DocumentNode.SelectNodes("//div[@class='row'] / div / article");

            foreach (HtmlNode ad in docs)
            {
                var url = ad.SelectSingleNode("div[@class='offer-item-details'] / header / h3 / a").Attributes["href"]
                          .Value;
                var title = ad.SelectSingleNode("div[@class='offer-item-details'] / header / h3 / a / span / span")
                            .InnerText.Trim();

                string idAds = ad.Attributes["data-tracking-id"].Value;

                var priceTemp =
                    ad.SelectSingleNode("div[@class='offer-item-details'] / ul / li[@class='offer-item-price']")
                    .InnerText.Trim();

                decimal price = ScrapExtensions.ConvertStringToDecimal(priceTemp);

                Ad ads = Ad.Create(Guid.NewGuid(), idAds, title, url, price, scanPage.Host, scanPage.HostUrl);

                adsList.Add(ads);
            }

            return(adsList);
        }
Exemplo n.º 3
0
        public List <Ad> ParseHomePage(HtmlDocument doc, ScanPageDto scanPage)
        {
            List <Ad>          adsList = new List <Ad>();
            HtmlNodeCollection docs    = doc.DocumentNode.SelectNodes("// tbody / tr[@class='wrap'] / td / div");

            foreach (HtmlNode ad in docs)
            {
                HtmlNode nod = ad.SelectSingleNode("table / tbody / tr[1]");

                string url = nod.SelectSingleNode("td[1] / a").Attributes["href"].Value;

                string title = nod.SelectSingleNode("td[2] / div / h3 / a / strong").InnerText.Trim();

                string idAds = ad.SelectSingleNode("table").Attributes["data-id"].Value;

                HtmlNode priceTemp = nod.SelectSingleNode("td[3] / div / p / strong");

                decimal price = ScrapExtensions.ConvertStringToDecimal(priceTemp?.InnerText);

                Ad ads = Ad.Create(Guid.NewGuid(), idAds, title, url, price, scanPage.Host, scanPage.HostUrl);

                adsList.Add(ads);
            }

            return(adsList);
        }
Exemplo n.º 4
0
        public async Task <Unit> Handle(CreateNewAd request, CancellationToken cancellationToken)
        {
            var username = await _userAccessor.GetUsername();

            var advertiser = await _context.Advertisers.SingleOrDefaultAsync(a => a.Username.ToLower() == username.ToLower(),
                                                                             cancellationToken);

            var ad = Ad.Create(request.Path, request.Price, advertiser);
            await _context.AddAsync(ad, cancellationToken);

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }