1

我正在尝试从 Instagram 个人资料中获取一些信息。我用 Google Chrome 生成了 XPath

//*[@id="react-root"]/section/main/article/div/div[1]/div

但是,什么也没找到。我只能找到

  //*[@id="react-root"]

这是一个**<span>**

没有别的了,有什么原因吗?难道我做错了什么?

var baseURL = "https://www.instagram.com/";

var client = new HtmlWeb();


var paginaPerfil = client.Load(baseURL + "belalao");


var nos = paginaPerfil.DocumentNode.SelectNodes("//*[@id='react-root']/section/main/article/div/div[1]/div");
            var quantidade = nos == null ? 0 : nos.Count;
4

1 回答 1

1

此时,https://www.instagram.com/belalao有一个空的<span id="react-root"></span>,因此您的代码按预期工作。也许您期望使用 React 组件填充 DOM 的 JavaScript 已经执行,但 HtmlAgilityPack 只会分析您下载的初始HTML,不会执行 JavaScript 并在之后进行分析。

查看页面上的源代码(与使用 DOM 检查器不同),您将看到它所看到的内容。

于 2016-07-05T00:24:15.123 回答