问题
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