我需要用给定的 url 筛选一个网站。当我尝试加载页面内容时 http://cks.nice.org.uk/?char=B ,我得到了所有内容(在下面的 doc 对象中),除了 div 中的链接( anchor 元素)与 class="list-wrapper"
有什么想法吗?谢谢
using System;
using HtmlAgilityPack;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
HtmlWeb web = new HtmlWeb();
HtmlDocument doc = null;
doc = web.Load("http://cks.nice.org.uk/?char=B");
}
最佳答案
我一般不熟悉 HtmlAgilityPack 或 C#,但我可以从抓取的角度告诉你我会做什么。
您需要获取的文件是http://cks.nice.org.uk/js/topics.txt它提供了主题名称及其 URL 的良好 JSON 结构。解析它,您会看到一组对象,例如:
{"Title":"Achilles tendinopathy","Slug":"achilles-tendinopathy","Specialities":["Injuries","Musculoskeletal"]},
{"Title":"Acne vulgaris","Slug":"acne-vulgaris","Specialities":["Skin and nail"]}
从每个页面中获取“Slug”并附加到基本 URL 以获取每个主题页面,例如http://cks.nice.org.uk/achilles-tendinopathy
关于c# - htmlagilitypack 未加载页面的全部内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18249471/