using System.Collections.Generic;
using System.Threading.Tasks;
using AngleSharp.Html.Parser;
using AngleSharp.Html.Dom;
static async Task Main(string[] args)
Console.WriteLine("Hello World");
var p = new ScrapieWeb();
await Task.Run(() => p.ScrapeWebsite());
private string Title { get; set; }
private string Url { get; set; }
private string siteUrl = "https://www.oceannetworks.ca/news-and-stories/stories/";
public string[] QueryTerms { get; } =
private void CleanUpResults(IElement result)
string htmlResult = result.InnerHtml.ReplaceFirst(" <span class=\"field-content\"><div><a href=\"", "https://www.oceannetworks.ca");
htmlResult = htmlResult.ReplaceFirst("\">", "*");
htmlResult = htmlResult.ReplaceFirst("</a></div>\n<div class=\"article-title-top\">", "-");
htmlResult = htmlResult.ReplaceFirst("</div>\n<hr></span> ", "");
private void SplitResults(string htmlResult)
string[] splitResults = htmlResult.Split('*');
internal async Task ScrapeWebsite()
CancellationTokenSource cancellationToken = new CancellationTokenSource();
HttpClient httpClient = new HttpClient();
HttpResponseMessage request = await httpClient.GetAsync(siteUrl);
cancellationToken.Token.ThrowIfCancellationRequested();
Stream response = await request.Content.ReadAsStreamAsync();
cancellationToken.Token.ThrowIfCancellationRequested();
HtmlParser parser = new HtmlParser();
IHtmlDocument document = parser.ParseDocument(response);
Console.WriteLine("Hello from ScrapeWebsite");
GetScrapeResults(document);
private void GetScrapeResults(IHtmlDocument document)
IEnumerable<AngleSharp.Dom.IElement> articleLink = null;
foreach (var term in QueryTerms)
articleLink = document.All.Where(x => x.ClassName == "views-field views-field-nothing" && (x.ParentElement.InnerHtml.Contains(term) || x.ParentElement.InnerHtml.Contains(term.ToLower()))).Skip(1);
Console.WriteLine("Hello from GetScrapeResults");
PrintResults(articleLink);
public void PrintResults(IEnumerable<IElement> articleLink)
foreach (var element in articleLink)
Console.WriteLine($"{Title} - {Url}{Environment.NewLine}");