zzzprojects / html-agility-pack

Html Agility Pack (HAP) is a free and open-source HTML parser written in C# to read/write DOM and supports plain XPATH or XSLT. It is a .NET code library that allows you to parse "out of the web" HTML files.
https://html-agility-pack.net
MIT License
2.65k stars 375 forks source link

[Feature request] Get element by ID #477

Open Ebola-Chan-bot opened 2 years ago

Ebola-Chan-bot commented 2 years ago

It's 2022 now and I don't know why you still don't have such a basic function: directly search an element by its ID, instead of having to know its actual path.

If you already have such a function then forgive me for not finding the relevant instructions in your documentation.

tewuapple commented 2 years ago

这是来自QQ邮箱的假期自动回复邮件。   您好,你的邮件已收到。 亮亮

elgonzo commented 2 years ago

It's 2022 now and I don't know why you still don't have heard about such basic things like XPath queries. :kissing_heart:

HAP has a function for XPath queries: https://html-agility-pack.net/select-nodes

XPath queries can be used to find/select nodes in a HTML (or XML) document by a variety of criteria, like for example to find element(s) with an id attribute having a certain value. For example, if you want to find any kind of element with an id "foobar", you could use the XPath query //*[@id='foobar'].

(I am not affiliated in any way with the HAP project. Just a user using the library in a couple of my projects...)

Ebola-Chan-bot commented 2 years ago

It's 2022 now and I don't know why you still don't have heard about such basic XML-related things like XPath queries. ;-)

HAP has a function for XPath queries: https://html-agility-pack.net/select-nodes

XPath queries can be used to find/select nodes in a XML document by a variety of criteria, like for example to find element(s) with an id attribute having a certain value. For example, if you want to find any kind of element with an id "foobar", you could use the XPath query //*[@id='foobar'].

(I am not affiliated in any way with the HAP project. Just a user using the library in a couple of my projects...)

Sorry, I'm really not very familiar with XPath. But I have also investigated some of your well-known competing products, such as Aspose.HTML, AngleSharp, etc. They all straightforwardly provide the GetElementById function and do not require users to understand XPath. I believe HAP would be more attractive if this function is added, since you specified HTML, where the ID attribute is specially defined, instead of a more general XML in the package title.

elgonzo commented 2 years ago

some of your well-known competing products

In case it got missed what i wrote at the end of my last comment: I am not representing the HAP project. I am not affiliated with the HAP project in any way.

Looking around a bit in the code base of HAP, its HtmlDocument class already has a GetElementById method:

https://github.com/zzzprojects/html-agility-pack/blob/c515e20e75e6e10991fd2acc3b96f9f5089b3a35/src/HtmlAgilityPack.Shared/HtmlDocument.cs#L659-L664

For reasons unknown to me, it's not appearing in the online documentation as far as i can tell. But then again, there is no real online API documentation of most of HAP's functionality anyway, so i guess it's par for the course with respect to HAP's documentation... :confused:

Ebola-Chan-bot commented 2 years ago

some of your well-known competing products

In case it got missed what i wrote at the end of my last comment: I am not representing the HAP project. I am not affiliated with the HAP project in any way.

Looking around a bit in the code base of HAP, its HtmlDocument class already has a GetElementById method:

https://github.com/zzzprojects/html-agility-pack/blob/c515e20e75e6e10991fd2acc3b96f9f5089b3a35/src/HtmlAgilityPack.Shared/HtmlDocument.cs#L659-L664

For reasons unknown to me, it's not appearing in the online documentation as far as i can tell. But then again, there is no real online API documentation of most of HAP's functionality anyway, so i guess it's par for the course with respect to HAP's documentation... 😕

Then this issue becomes to add the documentation … Many people won't bother to download it if they can't find the function they want in the documentation, especially when there're many other options.

elgonzo commented 2 years ago

Then this issue becomes to add the documentation …

True.