Beispiel #1
0
        public async void ScrapeGumtree(string search, int page, int sortType, int transType)
        {
            FilterOptions filterOptions = new FilterOptions(sortType, transType);
            List <Car>    GumtreeCars   = await Gumtree.ScrapeGumtree(search, page, filterOptions);

            Assert.NotEmpty(GumtreeCars);
        }
Beispiel #2
0
        // get all the car listing from the websties asynchronously
        public async Task <List <Car> > getCarsAsync(FilterOptions filterOptions, Toggles toggles, int page)
        {
            // scrape carsales based on toggle
            Task <List <Car> > CarsalesCars;

            if (toggles.ToggleCarsales)
            {
                CarsalesCars = Carsales.ScrapeCarsales(HeadlessBrowser.GetHtmlAsync, filterOptions, page);
            }
            else
            {
                CarsalesCars = Task.FromResult(new List <Car>());
            }

            // scrape facebook marketplace based on toggle
            Task <List <Car> > FbMarketplaceCars;

            if (toggles.ToggleFBMarketplace)
            {
                FbMarketplaceCars = FbMarketplace.ScrapeFbMarketplace(HeadlessBrowser.GetHtmlAsync, filterOptions, page);
            }
            else
            {
                FbMarketplaceCars = Task.FromResult(new List <Car>());
            }

            // scrape gumtree based on toggle
            Task <List <Car> > GumtreeCars;

            if (toggles.ToggleGumtree)
            {
                GumtreeCars = Gumtree.ScrapeGumtree(filterOptions, page);
            }
            else
            {
                GumtreeCars = Task.FromResult(new List <Car>());
            }

            // await all the taks in parallel at once
            await Task.WhenAll(FbMarketplaceCars, CarsalesCars, GumtreeCars);

            // create the list to the lenght of all the lists
            var Cars = new List <Car>(CarsalesCars.Result.Count + GumtreeCars.Result.Count + FbMarketplaceCars.Result.Count);

            // combine all the lists
            Cars.AddRange(CarsalesCars.Result);
            Cars.AddRange(FbMarketplaceCars.Result);
            Cars.AddRange(GumtreeCars.Result);

            // sort the list
            Sort(ref Cars, filterOptions.SortType);

            return(Cars);
        }