Alex
Alex

Reputation: 827

How to get content of Div using C#?

<div dir="ltr">
  <div>1 Tom</div>
  <div>2 Anna</div>
  <div>3 Alex</div>
  <div>4 Jax<br /></div>
</div>
<br />
<div class="gmail_quote">
  <div class="gmail_attr">
  .......Somethings  
</div>
</div>

How can I get all content inside tag <div dir="ltr"> like this :

1 Tom 2 Anna ...

Upvotes: 1

Views: 436

Answers (1)

Fka
Fka

Reputation: 6234

There is NuGet called called https://html-agility-pack.net/ which is pretty convenient to use:

var doc = new HtmlDocument();
doc.Load(filePath);

var query = $"div[@dir='ltr']";
HtmlNode node = doc.DocumentNode.SelectSingleNode(query);
string content = node.InnerHtml;

Upvotes: 2

Related Questions