Select items with data-url attribute using HTMLAgilityPack

I am writing a little Download-Roboter that is looking for links in the lower layers for myself.

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

I use html-agilitypack to find all a-href links.

Code example:

foreach (HtmlNode link in htmlDocument.DocumentNode.SelectNodes("//a[@href]"))
{
    HtmlAttribute attribute = link.Attributes["href"];
    links.Add(attribute.Value);
}

But I also want to find the data urls.

What XPath syntax should I use to search for URLs. Example url data in htmlcode:

    <div class="cbreplay" data-url="2012\edmonton\partien.pgn"></div>

I need "2012 \ edmonton \ partien.pgn" from this example. How can I figure this out with XPath syntax?

Best greetings, if I made some bad mistakes, tell me. This is my first question.

+5
source share
1 answer

, :

foreach (HtmlNode divNode in htmlDocument.DocumentNode.SelectNodes("//div[@data-url]"))
{
    HtmlAttribute attribute = divNode.Attributes["data-url"];
    links.Add(attribute.Value);
}

, //div[@data-url] data-url. .

, div , //*[@data-url] .

+11

All Articles