简体   繁体   中英

Website parsing c# - Html Agility Pack

I want to parse <a href=""></a> tag of a website. I am trying to get the href attribute value present in each of such 'description' span classes.

在此处输入图片说明

I tried the following code

HtmlNodeCollection sp = htmlDocument.DocumentNode.SelectNodes("//span[@class='description']//a");
                        foreach (HtmlNode link in sp)
                        {
                            HtmlAttribute att = link.Attributes["href"];
                            System.Diagnostics.Debug.WriteLine(att.Value);
                        }

I am not able to get the href attribute value. What is my mistake ?

在此处输入图片说明 You can use chrome developer tools (F12), it can help you easy to get correct xPath syntax (Copy XPath)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM