Ejemplo n.º 1
0
        public override async Task <IEnumerable <ListingBase> > ParseListingsAsync(string html, CancellationToken ct)
        {
            return(await Task.Run(() =>
            {
                var listings = new HashSet <ListingBase>();
                var doc = new HtmlDocument();
                doc.LoadHtml(html);
                try
                {
                    var nodes = doc.DocumentNode.SelectNodes("//div[contains(@class,'complete-serp-result-div')]");
                    if (nodes != null)
                    {
                        foreach (var node in nodes)
                        {
                            var listing = new DiceListing();
                            listing.ParseInitialNode(node);
                            listings.Add(listing);
                        }
                    }
                }
                catch (Exception e)
                {
                    // do something useful here
                }

                return listings;
            },
                                  ct));
        }
Ejemplo n.º 2
0
        public static ListingBase ListingFactory(WebSource webSource, HtmlNode node)
        {
            ListingBase listing;

            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (webSource)
            {
            case WebSource.Craigslist:
                listing = new CraigslistListing();
                break;

            case WebSource.Indeed:
                listing = new IndeedListing();
                break;

            case WebSource.Monster:
                listing = new MonsterListing();
                break;

            case WebSource.StackOverflow:
                listing = new StackOverflowListing();
                break;

            case WebSource.Dice:
                listing = new DiceListing();
                break;

            case WebSource.None:
                listing = new UnknownListing();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(webSource), webSource, null);
            }

            listing.ParseInitialNode(node);
            return(listing);
        }