htmlagilitypack通过名称获取元素的节点 [英] htmlagilitypack getting an element's node by the name

查看:90
本文介绍了htmlagilitypack通过名称获取元素的节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过名称获取元素的节点.有GetElementById,为什么没有GetElementByName.有问题的元素是:

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:请删除该问题已得到回答.完全错误,请自己尝试.node.Name不是属性'name'的名称,它不是我需要的标记名.

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.

推荐答案

您没有访问后代中"select"标签的名为"name"的节点属性.您正在使用标记的属性名称(xe.Name).正确的方法可以是:

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));

这篇关于htmlagilitypack通过名称获取元素的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆