/// <inheritdoc /> public 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("//ul/li[contains(@class,'result-row')]/p[contains(@class,'result-info')]"); if (nodes != null) { foreach (var node in nodes) { var listing = new CraigslistListing(); listing.ParseInitialNode(node); listings.Add(listing); } } } catch (Exception e) { // do something useful here } return listings; }, ct)); }
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); }