/// <inheritdoc cref="UrlFetcher" /> public override async Task <ListingBase> GetRemainingListingDataAsync(ListingBase listing, CancellationToken ct) { return(await Task.Run(async() => { try { // get the description, employment type & salary range using (var wc = WebClientFactory()) { var html = await wc.DownloadStringTaskAsync(listing.ListingUrl); listing = await Parser.ParseListingDataAsync(html, listing, ct); // get the reply information var replyLink = await Parser.ParseReplyLinkAsync(html, ct); if (!string.IsNullOrEmpty(replyLink)) { html = await wc.DownloadStringTaskAsync(new Uri(listing.ListingUrl.GetLeftPart(UriPartial.Authority) + replyLink)); listing = await Parser.ParseListingReplyAsync(html, listing, ct); } } } catch (WebException we) { // do useful stuff here } return listing; }, ct)); }
/// <inheritdoc /> public async Task <ListingBase> ParseListingReplyAsync(string html, ListingBase listing, CancellationToken ct) { return(await Task.Run(() => { var doc = new HtmlDocument(); doc.LoadHtml(html); try { var node = doc.DocumentNode.SelectSingleNode("//p[contains(@class,'reply-email-address')]"); if (node != null) { node = node.SelectSingleNode("./a"); if (node != null) { listing.ApplyEmail = new EmailInfo(node.Attributes[Href].Value); } } } catch (Exception e) { // do something useful here } return listing; }, ct)); }
/// <inheritdoc cref="SiteSearcher" /> private async Task ProcessURL(Uri url, CancellationToken ct) { var listings = await Fetcher.GetListingsAsync(url, ct); if (listings != null) { ListingBase tmpListing = null; try { foreach (var listing in listings) { tmpListing = listing; // get the description and the apply email await Fetcher.GetRemainingListingDataAsync(listing, ct); Listings.Add(listing); } } catch (Exception e) { var vm = new OkViewModel(e.Message + "\n" + url + "\n" + tmpListing, "Search Error"); DialogService.OpenDialog(vm, null); } } }
public void ConstructorAndPropertiesTests(WebSource webSource, string listFileString, string xPath) { var html = HelperMethods.LoadFromFile(listFileString); if (!string.IsNullOrEmpty(html)) { _node = HelperMethods.GetNodeFromHtml(html, xPath); if (_node != null) { Listing = HelperMethods.ListingFactory(webSource, _node); Assert.IsNotNull(Listing.ListingUrl); if (webSource != WebSource.Craigslist) { Assert.IsTrue(!string.IsNullOrEmpty(Listing.Company)); Assert.IsTrue(!string.IsNullOrEmpty(Listing.City)); } Assert.IsNotNull(Listing.ListingTime); Assert.IsTrue(!string.IsNullOrEmpty(Listing.Heading)); } else { Assert.Fail("Node should not be null."); } } else { Assert.Fail("html should not be null."); } }
/// <inheritdoc /> public async Task <ListingBase> ParseListingDataAsync(string html, ListingBase listing, CancellationToken ct) { return(await Task.Run(() => { var doc = new HtmlDocument(); doc.LoadHtml(html); try { var node = doc.DocumentNode.SelectSingleNode("//section[contains(@class,'userbody')]"); if (node != null) { listing.ParseRemainingData(node); } } catch (Exception e) { // do something useful here } return listing; }, ct)); }
public override Task <ListingBase> GetRemainingListingDataAsync(ListingBase listing, CancellationToken ct) { throw new NotImplementedException(); }
public async Task <ListingBase> ParseListingReplyAsync(string html, ListingBase listing, CancellationToken ct) { throw new NotImplementedException(); }