List<BlogInfo> blog = new List<BlogInfo>(); HtmlWeb web = new HtmlWeb(); HtmlNodeCollection node; for (int i = 0; i < 10; i++) { node = web.Load($"https://www.cnblogs.com/#p{i}").DocumentNode.SelectNodes("//a[@class=‘post-item-title‘]"); foreach (var item in node) { blog.Add(new BlogInfo { Title = item.InnerText, Content = web.Load(item.GetAttributeValue("href", "")).DocumentNode.SelectSingleNode("//div[@id=‘cnblogs_post_body‘]").InnerHtml }); } }
参考https://www.cnblogs.com/cplemom/p/13388613.html