WireCoder
WireCoder

Reputation: 45

VB.net Can you read the text in a certain Div

I was wondering if you read text in a certain div so when the html code says:

<html>
<head>
</head>
<body>
<div id="Main">SomeText</div>
<div id="Text">Welcome to my website</div>
</body>
</html>

i only want to see 'Welcome to my website' in the textbox 1.

is there anyone who knows how i can do that?

any help would be much appreciated.

Upvotes: 0

Views: 1105

Answers (3)

Tim Schmelter
Tim Schmelter

Reputation: 460058

I would use HtmlAgilityPack, then it's easy as:

Dim html = System.IO.File.ReadAllText("path")
Dim doc = New HtmlAgilityPack.HtmlDocument()
doc.LoadHtml(html)
Dim welcomeDiv = doc.GetElementbyId("Text")
Me.TextBox1.Text = welcomeDiv.InnerText

Upvotes: 0

Dave
Dave

Reputation: 355

I would recommend the HTML Agility pack hosted on codeplex at http://htmlagilitypack.codeplex.com/. With it you can connect to a HTML source, load the HTML into an reasonably friendly navigator and use XML type queries to traverse and manipulate the HTML.

Upvotes: 0

bjnr
bjnr

Reputation: 3437

Mark your div with runat="server":

<div id="TextDiv" runat="server">Welcome to my website</div>

then access the text in VB.NET code:

TextDiv.InnerHtml 

Upvotes: 1

Related Questions