Analyze Html with c#

Asked 2 years ago, Updated 2 years ago, 43 views

Creating a desktop app in c#.
I've been stuck before, so please help me.
Analyzing Html in webbrowser.
I would like to do the following two things, but can I use only the HtmlElement class?If not, I would appreciate it if you could let me know the recommended package.

H Identified several tags by Html tag name.Determined which tag has the desired element among the identified tags.A value of the href element of the second tag of the specified tag is acquired.(Two tags means two tags out of the entire first Html source)

HIdentified some tags by the tag name of Html.Displays all the contents (source) of the tag with the desired element among the identified tags.

I could go to the point of identifying a tag (Html Element, Object) with the desired element from some tags (Html Element Collection) identified by .GetByTagName, .GetByAttribute, etc., but I couldn't see all the contents or get the next two tags.>
I'm a beginner and I'm confused about how to handle collections and objects.I feel that the concept of objects is a hindrance to my work this time.I think I can go if it's just an array...

Please help me with just the policy.

c# html

2022-09-30 16:43

1 Answers

The Html Agility Pack is a well-known tool for parsing HTML in C#.
You can use XPath to facilitate retrieval by tag name as follows:

var htmlDoc=new HtmlDocument();
htmlDoc.LoadHtml(html);

string name = htmlDoc.DocumentNode
    .SelectNodes("//td/input")
    .First()
    .Attributes ["value"].Value;


2022-09-30 16:43

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.