using System.Collections.Generic;
using System.Threading.Tasks;
private readonly HttpClient _httpClient;
public async static Task Main()
var program = new Program();
var movieRatings = await program.GetMovieRatingsAsync("vieekk", 0);
_httpClient = new HttpClient();
_httpClient.BaseAddress = new Uri("https://www.filmtipset.se/");
public async Task<IEnumerable<MovieRatingScrape>> GetMovieRatingsAsync(string username, int page)
var response = await _httpClient.GetAsync($"/betyg/{username}?p={page}");
response.EnsureSuccessStatusCode();
var html = await response.Content.ReadAsStringAsync();
return new MovieRatingsHtmlMapper().Map(html);
public class MovieRatingsHtmlMapper
public IEnumerable<MovieRatingScrape> Map(string html)
var htmlDocument = new HtmlDocument();
htmlDocument.LoadHtml(html);
return Map(htmlDocument);
public IEnumerable<MovieRatingScrape> Map(HtmlDocument item)
var movieRatings = new List<MovieRatingScrape>();
var nodes = item.DocumentNode.SelectNodes("//table[@class='list']/tr");
foreach (var node in nodes)
Console.WriteLine(node.InnerHtml);
var movieRating = new MovieRatingScrape
Date = DateTime.Parse(node.SelectSingleNode(".//td[2]")?.InnerText),
Slug = node.SelectSingleNode(".//td[1]/a[starts-with(@href, '/film/')]")?
.GetAttributeValue("href", null)?
.Replace("/film/", string.Empty),
SwedishTitle = node.SelectSingleNode(".//td[1]/a")?.InnerText
Console.WriteLine($"{movieRating.Slug}, {movieRating.SwedishTitle}, {movieRating.Date}");
movieRatings.Add(movieRating);
Console.WriteLine("---");
public class MovieRatingScrape
public DateTime Date { get; set; }
public string Slug { get; set; }
public string SwedishTitle { get; set; }