htmlagilitypack getting an element's node by the name

試著忘記壹切 提交于 2021-01-28 12:24:32

问题


How can I get the node of an element by the name. There is GetElementById, why no GetElementByName. The element in question is:

   <select class="box1" name="DAY" tabindex="31"> … </select>

I want to be able to get this node. But I have no idea how.

Pete: please remove that this question has been answered. It is totally WRONG go try it yourself. the node.Name is not the name of the attribute 'name' its the tagname which is NOT what I need.


回答1:


You are not accessing the node attribute called "name" of the "select" tags in the descendants. You are using the property Name of the tag (xe.Name). The correct approach can be :

document.DocumentNode.Descendants("select").Where(node => node.GetAttributeValue("name", "").Equals("DAY", StringComparison.InvariantCultureIgnoreCase));


来源:https://stackoverflow.com/questions/18107125/htmlagilitypack-getting-an-elements-node-by-the-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!