How to select nodes via HtmlAgilityPack?
-
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(); } } }
-
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(); } } }
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]
-
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]
thanks for your reply Could you tell me how can I add the breakpoint in doc?