Home > DeveloperSection > Forums > HTML Agility pack with c#
Tanuj Kumar

Total Post:134

Points:940
Posted on    June-03-2015 7:03 AM

 HTML C#  HTML5 
Ratings:


 1 Reply(s)
 583  View(s)
Rate this:

c# code:`

var node = new HtmlWeb();

                var doc = node.Load("http://ask.fm/");

                HtmlNode ournode = doc.DocumentNode.SelectSingleNode("//div[@id='heads']")

                textBox1.Text=ournode.InnerHtml;

` html code :

//< div id="heads" >

 

      <a href="/sudenur3434" data-rlt-aid="welcome_head"><img alt="" class="head" id="face_30132803" src=" thumb_tiny/IMG_20150513_192250.jpg" /></a>

      <a href="/leylaulucay" data-rlt-aid="welcome_head"><img alt="" class="head" id="face_56578735" src="thumb_tiny/11094711_919135961470973_149663457_njpg720960png1280963.png" /></a>

 

I want to see the following in the text box

/sudenur3434

/leylaulucay



Kamlakar Singh
Kamlakar Singh

Total Post:194

Points:1396
Posted on    June-03-2015 7:09 AM

I have added an additional line to your code:

var node = new HtmlWeb();

var doc = node.Load("http://ask.fm/");

HtmlNode ournode = doc.DocumentNode.SelectSingleNode("//div[@id='heads']")

var val = ournode.Attributes["href"].Value;

textBox1.Text=val;

This would let you get the href attribute. Simply use the same code to get the other nodes href value and then add them to your textbox


Don't want to miss updates? Please click the below button!

Follow MindStick