public async Task<List<Post>> GetBlogCounters(List<Post> postLink, HttpClient httpClient)
{
HtmlDocument doc = new HtmlDocument();
foreach (var post in postLink)
{
var request = new HttpRequestMessage(HttpMethod.Get, new Uri(post.Url));
var response = await httpClient.SendRequestAsync(request);
doc.LoadHtml(await response.Content.ReadAsStringAsync());
var details = doc.DocumentNode.Descendants("section")
.Where(d => d.Attributes.Contains("class") &&
d.Attributes["class"].Value.Contains("user-info")).LastOrDefault();
if (details != null)
{
var divs = details.Descendants("div").ToList();
if (divs.Count >= 12)
{
post.VisitorsCounter = int.Parse(divs[9].InnerText);
post.CommentsCounter = int.Parse(divs[12].InnerText);
post.DateLastModification = DateTime.ParseExact(divs[5].InnerText,
"dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture);
}
}
}
return postLink;
}