0
votes

I have hit a wall with this one, please could someone help me out?

From the URL below I am looking to get to the inner text of

<a href="/borsa/azioni/scheda.html?isin=IT0001233417&lang=en">A2A</a>

The XPath syntax I am using doesn't return any data:

.//table[@class='table_dati']//tbody[@class='constituents']//tr//td[@class='name']//a

The URL is http://www.borsaitaliana.it/borsa/azioni/ftse-mib/lista.html?lang=en&page=1

Thanks in advance,

Grant

3

3 Answers

2
votes

How about //tbody[@class='constituents']//td[@class='name']/a? This should work pretty well, actually.

2
votes

Your XPath starts with ., so it is relative to the context node. But you haven't told us anything about the context. Maybe you want to omit the initial . and make it "absolute":

//table[@class='table_dati']/tbody[@class='constituents']/tr/td[@class='name']/a

I would also change the // to / wherever you're looking for a direct child (not descendant in general) relationship.

0
votes

From my experience, HTMLAgilityPack doesn't play nice with the tbody tag. I just follow up the table with the tr td to find the right cell, skipping tbody altogether.