extracting specific links from a web page

using html agility pack i am trying to extract links from a webpage. I can extract all links using the following code. But there is a table on this page with id="table1". I only want links present inside that table. What shall i change in this code(guess i need to modify only my xpath expression, but how shall i write xpath expression) to just extract links from that part of the page?    
protected void Page_Load(object sender, EventArgs e)
    {

        HtmlAgilityPack.HtmlWeb web = new HtmlWeb();
        HtmlAgilityPack.HtmlDocument doc = web.Load("http://www.eppi.ioe.ac.uk/cms/Default.aspx?tabid=62");

        List<string> hrefTags = new List<string>();

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

                int i = 0;

    }

Open in new window

mmalik15Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
Try this:

foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//table[@id=\"table1\"//a[@href]"))

Open in new window

0
mmalik15Author Commented:
thanks for the comment but getting the following exception

'//table[@id="table1"//a[@href]' has an invalid token.
0
mmalik15Author Commented:
the complete method is

 
protected void Page_Load(object sender, EventArgs e)
    {

        HtmlAgilityPack.HtmlWeb web = new HtmlWeb();
        HtmlAgilityPack.HtmlDocument doc = web.Load("http://www.eppi.ioe.ac.uk/cms/Default.aspx?tabid=62");

        List<string> hrefTags = new List<string>();

        foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//table[@id=\"table1\"//a[@href]"))
        {
            HtmlAttribute att = link.Attributes["href"];
            hrefTags.Add(att.Value);
        }

                int i = 0;

    }

Open in new window

0
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

mmalik15Author Commented:
I have read a couple of issues online where this problem was caused by some invalid characters in the xml but It works okay with the following line of code so i assume its not any invalid character in that xml

foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]"))
0
käµfm³d 👽Commented:
My fault. There should be a closing bracket on the first attribute selector:

foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//table[@id=\"table1\"]//a[@href]"))

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mmalik15Author Commented:
sorry I should have realised the missing bracket :(. But thanks kaufmed. you 're a start buddy :)
0
mmalik15Author Commented:
*star
0
käµfm³d 👽Commented:
NP. Glad to help  = )
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.