How to extract links from a div
-
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.
-
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.
Xpath?
-
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.
Parse the div content and look for the
a
orhref
tags within that text.Apps - Color Analyzer | Arctic | XKCD | Sound Meter | Speed Dial
-
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.
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"); } } } }
-
Parse the div content and look for the
a
orhref
tags within that text.Apps - Color Analyzer | Arctic | XKCD | Sound Meter | Speed Dial
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.
-
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.
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.