Exemplo n.º 1
0
 private static void TimerOnElapsed(object sender, ElapsedEventArgs e)
 {
     Task.Run(async() =>
     {
         var supplier  = new ScratchSupplier("https://wykop.pl");
         var htmlPage  = await supplier.GetPage();
         var extractor = new WykopTitlesExtractor();
         var headers   = extractor.ExtractNews(htmlPage);
         bootstrapper.PublishNews(headers);
     }).GetAwaiter().GetResult();
 }
Exemplo n.º 2
0
        public void CanParseNewsLines()
        {
            var path   = GetFullFilePath("Test_data\\page.html");
            var html   = File.ReadAllText(path);
            var parser = new WykopTitlesExtractor();
            var titles = parser.ExtractNews(html);

            foreach (var newsLine in titles)
            {
                Assert.NotEmpty(newsLine.Title);
                Assert.NotEmpty(newsLine.ImgUrl);
                Assert.True(newsLine.Tags.Any());
                Assert.NotEmpty(newsLine.Attributes.Single(e => e.Key == "id").Value);
                var time = newsLine.Attributes.SingleOrDefault(a => a.Key == "time").Value;
                Assert.True(DateTime.TryParse(time, out DateTime dt));
            }
        }