如何获得“课堂” VB中HTML元素的属性 [英] How to get "class" attribute of an HTML element in VB

查看:72
本文介绍了如何获得“课堂” VB中HTML元素的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述







如何获取HTML元素的class属性。

< br $>


class =button



你怎么做这个你知道吗



i知道如何通过id获取元素,但不知道如何获取元素

Hi,


How to get "class" attribute of an HTML element.


class="button"

How do you do this do you know

i know how to get an element by id, but not class

推荐答案

正式答案是这样的:你总能得到一个元素由 id ,因为 id 始终是唯一的。对于HTML类,许多元素可以使用相同的类。所以,你正在寻找的方法是不存在的。



这并不意味着你有任何明确的行动方案。也许你可以解释一下你想要达到什么目的,为什么...







例如,如果您使用 System.Windows.Forms.HtmlDocument ,则可以遍历以 System.Windows.Forms开头的所有可用元素。 .HtmlDocument.All 或者通过获取元素集合System.Windows.Forms.HtmlDocument.GetElementsByTagName (如果你只需要一个已知标签的元素)并且,对于每个元素,使用 System.Windows.Forms.HtmlElement.GetAttribute 检查其类属性。请参阅:

http://msdn.microsoft .com / zh-cn / library / system.windows.forms.webbrowser.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser.document.aspx [ ^ ],

http://msdn.microsoft.com/en -us / library / system.windows.forms.htmldocument.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.windows.forms。 htmlelement.aspx [ ^ ]。



很简单。并且不要认为如果你有一个现成的方法GetElementByClass返回元素集合,它会更快。如果你用某个类的元素写你的方法做你想要的,那就恰到好处。



如果你需要别的东西,或者你请使用不同的库,请说明。感谢您的澄清;看起来我的 System.Windows.Forms.HtmlDocument 的配方对你有用。



-SA
The formal answer is this: you can always get an element by id, because the id is always unique. As to the HTML class, many elements can use the same class. So, the method you are looking for cannot exist.

This does not suggest you any definitive course of action. Probably it could be possible if you explain what do you want to achieve, why…



For example, if you are working with System.Windows.Forms.HtmlDocument, you could traverse all available elements starting with System.Windows.Forms.HtmlDocument.All or get a collection of elements by System.Windows.Forms.HtmlDocument.GetElementsByTagName (if you only need an element of known tag) and, for each element, check its class attribute using System.Windows.Forms.HtmlElement.GetAttribute. Please see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser.document.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.htmldocument.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.htmlelement.aspx[^].

Pretty easy. And don''t think that if you had a ready-to-use method "GetElementByClass" returning the collection of elements, it would be faster. If you write your method doing what you want with the element of certain class, it would be just right.

If you need something else, or if you use different library, please explain. Thank you for clarification; it looks like my recipe for System.Windows.Forms.HtmlDocument will work for you.

—SA


由于class是保留字,Microsoft使用className而不是class,在C#中有相同的问题
Since class is a reserved word, Microsoft used className instead of class, had same issue in C#


这篇关于如何获得“课堂” VB中HTML元素的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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