HTML AGILITY PACK WITH C#

Tanuj Kumar

Total Post:134

Points:940
Posted by  Tanuj Kumar
C#  HTML5 
 1156  View(s)
Ratings:
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

  1. Kamlakar Singh

    Post:194

    Points:1396
    Re: HTML Agility pack with c#

    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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!