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 select nodes via HtmlAgilityPack?

How to select nodes via HtmlAgilityPack?

Scheduled Pinned Locked Moved C#
csharpcomregexxmltutorial
3 Posts 2 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.
  • M Offline
    M Offline
    MohammadRSZ
    wrote on last edited by
    #1

    I have just practise to grab some data from a web page.
    Of course, I am new in c#.
    I am using regex but it does not word. and return null.

    using HtmlAgilityPack;

    namespace ConsoleApp1
    {
    
    
        class Program
        {
            static void Main(string\[\] args)
            {
                HtmlWeb web = new HtmlWeb();
                HtmlDocument doc = web.Load("https://www.videoblocks.com/video/after-effects-cs5-template-bracket-titles-65zdx8e");
    
                var title = doc.DocumentNode.SelectNodes(xpath: "//ul\[@class='stockItemInfo-stockSpec'\]").FirstOrDefault().InnerText.Split(':').FirstOrDefault();
                var secp = doc.DocumentNode.SelectNodes("//ul\[@class='stockItemInfo-stockSpec'\]//li//span").FirstOrDefault().InnerText;
    
    
                Console.Write(title+":"+secp);
                    Console.ReadKey();
            }
        }
    }
    
    K 1 Reply Last reply
    0
    • M MohammadRSZ

      I have just practise to grab some data from a web page.
      Of course, I am new in c#.
      I am using regex but it does not word. and return null.

      using HtmlAgilityPack;

      namespace ConsoleApp1
      {
      
      
          class Program
          {
              static void Main(string\[\] args)
              {
                  HtmlWeb web = new HtmlWeb();
                  HtmlDocument doc = web.Load("https://www.videoblocks.com/video/after-effects-cs5-template-bracket-titles-65zdx8e");
      
                  var title = doc.DocumentNode.SelectNodes(xpath: "//ul\[@class='stockItemInfo-stockSpec'\]").FirstOrDefault().InnerText.Split(':').FirstOrDefault();
                  var secp = doc.DocumentNode.SelectNodes("//ul\[@class='stockItemInfo-stockSpec'\]//li//span").FirstOrDefault().InnerText;
      
      
                  Console.Write(title+":"+secp);
                      Console.ReadKey();
              }
          }
      }
      
      K Offline
      K Offline
      Keviniano Gayo
      wrote on last edited by
      #2

      You can check the documentation in Html Agility Pack - documentation[HTML Agility Pack] It is different from regex. You can hit a breakpoint in "doc" variable and debug, then it will be easier to inspect the elements on how to navigate it.

      [Signature space for sale]

      M 1 Reply Last reply
      0
      • K Keviniano Gayo

        You can check the documentation in Html Agility Pack - documentation[HTML Agility Pack] It is different from regex. You can hit a breakpoint in "doc" variable and debug, then it will be easier to inspect the elements on how to navigate it.

        [Signature space for sale]

        M Offline
        M Offline
        MohammadRSZ
        wrote on last edited by
        #3

        thanks for your reply Could you tell me how can I add the breakpoint in doc?

        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