Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to extract links from a div

How to extract links from a div

Scheduled Pinned Locked Moved C#
tutorialdata-structureshelpquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    faiza butt89
    wrote on last edited by
    #1

    Hello everyone, I am working on a project and need your help. I have a div having the search results in the form of links or URLs . Now I want to save them in a file. Can anyone guide me that how can I extract and save those links from div to variables or any simple data structures like array or arraylist. Waiting for quick response! Thanks in advance.

    P A A F 4 Replies Last reply
    0
    • F faiza butt89

      Hello everyone, I am working on a project and need your help. I have a div having the search results in the form of links or URLs . Now I want to save them in a file. Can anyone guide me that how can I extract and save those links from div to variables or any simple data structures like array or arraylist. Waiting for quick response! Thanks in advance.

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      Xpath?

      1 Reply Last reply
      0
      • F faiza butt89

        Hello everyone, I am working on a project and need your help. I have a div having the search results in the form of links or URLs . Now I want to save them in a file. Can anyone guide me that how can I extract and save those links from div to variables or any simple data structures like array or arraylist. Waiting for quick response! Thanks in advance.

        A Offline
        A Offline
        Abhinav S
        wrote on last edited by
        #3

        Parse the div content and look for the a or href tags within that text.

        Apps - Color Analyzer | Arctic | XKCD | Sound Meter | Speed Dial

        F 1 Reply Last reply
        0
        • F faiza butt89

          Hello everyone, I am working on a project and need your help. I have a div having the search results in the form of links or URLs . Now I want to save them in a file. Can anyone guide me that how can I extract and save those links from div to variables or any simple data structures like array or arraylist. Waiting for quick response! Thanks in advance.

          A Offline
          A Offline
          Akii Malam
          wrote on last edited by
          #4

          First find the div in contentplace holder like this make sure u have an atribute of runat="server" in ur div and controls you want to find. public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { ContentPlaceHolder myContent = (ContentPlaceHolder)this.Master.FindControl("ContentPlaceHolder1"); System.Web.UI.Control Testdiv = myContent.FindControl("TestDiv1"); System.Web.UI.Control anchor1 = Testdiv1.FindControl("Your Anchor id"); } } } }

          1 Reply Last reply
          0
          • A Abhinav S

            Parse the div content and look for the a or href tags within that text.

            Apps - Color Analyzer | Arctic | XKCD | Sound Meter | Speed Dial

            F Offline
            F Offline
            faiza butt89
            wrote on last edited by
            #5

            Thank you for reply. Actually now I am trying t parse div but y code is not working. Here it is :

                HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                doc.Load(this.Page.MapPath("~/Default2.aspx"));
                HtmlNodeCollection bodyNodes = doc.DocumentNode.SelectNodes("//div\[@id='wrapper'\]/a\[@href\]");
                foreach (var node in bodyNodes)
                {
                    string href = node.Attributes\["href"\].Value;
                }
            

            But the selected nodes are empty. May be because it only has content on runtine otherwise its empty. How to get div data on runtime ? Please help.

            1 Reply Last reply
            0
            • F faiza butt89

              Hello everyone, I am working on a project and need your help. I have a div having the search results in the form of links or URLs . Now I want to save them in a file. Can anyone guide me that how can I extract and save those links from div to variables or any simple data structures like array or arraylist. Waiting for quick response! Thanks in advance.

              F Offline
              F Offline
              faiza butt89
              wrote on last edited by
              #6

              Thank you for reply. Actually now I am trying t parse div but y code is not working. Here it is :

                  HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
              
                  doc.Load(this.Page.MapPath("~/Default2.aspx"));
              
                  HtmlNodeCollection bodyNodes = doc.DocumentNode.SelectNodes("//div\[@id='wrapper'\]/a\[@href\]");
                  foreach (var node in bodyNodes)
                  {
                      string href = node.Attributes\["href"\].Value;
                  }
              

              But the selected nodes are empty. May be because it only has content on runtine otherwise its empty. How to get div data on runtime ? Please help.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups