Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# HtmlAgilityPack-如何获得单引号中包含的属性值?_C#_Html Agility Pack - Fatal编程技术网

C# HtmlAgilityPack-如何获得单引号中包含的属性值?

C# HtmlAgilityPack-如何获得单引号中包含的属性值?,c#,html-agility-pack,C#,Html Agility Pack,我有以下HTML: <div id="search_posts"> <article class="xxx" data-id='79642521778' data-type='photoset' <!-- many other attributes in single quotes-->> Article text 1 </article> <article class="xxx" data-id='84701653287' data-t

我有以下HTML:

<div id="search_posts">
<article class="xxx"  data-id='79642521778' data-type='photoset' <!-- many other attributes in single quotes-->> Article text 1 </article>
<article class="xxx"  data-id='84701653287' data-type='photoset' <!-- many other attributes in single quotes-->> Article text 2 </article>
</div>

它返回NULL。如何获得正确的值?谢谢。

您正在尝试获取
doc.document节点
上的
数据id
属性,而不是您的
文章
节点

var articles = doc.GetElementbyId("search_posts").SelectNodes("//article");
var firstDataId = articles.First().GetAttributeValue("data-id", "NULL");

不确定,HtmlAgilityPack仍然是最好的工具。看见考虑一下,哦,我忘了在我的代码中添加1行代码。但我已经根据你的回答重写了。谢谢
var articles = doc.GetElementbyId("search_posts").SelectNodes("//article");
var firstDataId = articles.First().GetAttributeValue("data-id", "NULL");