c# - Select elements with attribute data-url using HTMLAgilityPack -


I'm writing a little bit of download-robot, which is looking for links in the lower layers

I can find all the links in an HTML page (links to .pgn, .pdf, .html, .... as well as links to .jpg files) - files

I have all one- I'm using HTML-agilitypack to find href links.

Sample code:

  foreach (html.document link html.document.DocumentNode.SelectNodes ("// a [@heref] ")) {HTMLtml attribute = link.Attributes [" href "]; Links.Add (attribute.Value); }   

But I have to get the data-url I

What XPath-syntax I want to use to find the data-url is an example data-url in i html code :

  & lt; Div class = "cbreplay" data-url = "2012 \ edmonton \ partien.pgn" & gt; & Lt; / Div & gt; I need "2012 \ edmonton \ partien.pgn" from this example. How can I feel it with XPath syntax?  

Good luck, if I made some bad mistakes, then tell me. This is my first question.

The following should do you:

  foreach (html.dode divNode in htmlDocument .DocumentNode.SelectNodes ("// div [@ data-url]") {HTML attribute attribute = divNode.Attributes ["data-url"]; Links.Add (attribute.Value); }   

Effectively, the statement // div [@ data-url] should select all the nodes with the data-url attribute. We then drag this feature.

If this feature has nodes other than divs, then // * [@ data-url] should be tricked.

Comments