HtmlAgilityPack - How to get the tag by Id?

寵の児 提交于 2019-12-01 02:12:47
nrkz

If I understand correctly then:

HtmlAgilityPack.HtmlDocument document2 = new HtmlAgilityPack.HtmlDocument();
document2.Load(@"C:\try.html");

string tag = document2.GetElementbyId("yourid").Name;
string href = document2.GetElementbyId("yourid").GetAttributeValue("href", "");

You can use the following XPath to find item element by its id attribute value :

var id = "Back";
var query = $"//manifest/item[@id='{id}']";
HtmlNode node = document2.DocumentNode.SelectSingleNode(query);
string href = node.GetAttributeValue("href", "");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!