public async Task <IList <Question> > ParseList() { List <Question> result = new List <Question>(); string html = await _downloadProvider.DownloadPage("https://toster.ru/questions/latest"); var document = new HtmlParser().Parse(html); var cells = document.QuerySelectorAll("ul.content-list li.content-list__item"); foreach (var cell in cells) { var titleTag = cell.QuerySelector("h2 a"); string title = titleTag?.TextContent; string url = titleTag?.GetAttribute("href"); if (string.IsNullOrWhiteSpace(title) || string.IsNullOrWhiteSpace(url)) { continue; } result.Add(new Question { Title = title.Trim(), Url = Uri.UnescapeDataString(url.Trim()), Provider = QuestionProvider.Toster, }); } return(result); }
public async Task <IList <Question> > ParseList() { List <Question> result = new List <Question>(); string html = await _downloadProvider.DownloadPage("http://ru.stackoverflow.com/"); var document = new HtmlParser().Parse(html); var rows = document.QuerySelectorAll("div.question-summary div.summary"); foreach (var row in rows) { var titleTag = row.QuerySelector("h3 a"); string title = titleTag?.TextContent; string url = titleTag?.GetAttribute("href"); if (string.IsNullOrWhiteSpace(title) || string.IsNullOrWhiteSpace(url)) { continue; } var tagTags = row.QuerySelectorAll("div.tags a"); ; result.Add(new Question { Title = title.Trim(), Url = "https://ru.stackoverflow.com" + Uri.UnescapeDataString(url.Trim()), Provider = QuestionProvider.Stackoverflow, Tags = tagTags.Select(x => x?.TextContent).Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => x.Trim()).ToList() }); } return(result); }