GetElementById return incorrect nodes

Clash Royale CLAN TAG#URR8PPP
GetElementById return incorrect nodes
I'm encountered a little problem (I don't know if I did some mistake or if is a bug) while parsing this page.
I'm trying to get all the a tag available in this table:
a

so for achieve this, I wrote this code:
`var d = doc.GetElementbyId("odds-data-table");
HtmlNodeCollection listItems = d.SelectNodes("//a");`
in particular d contains the table structure that I want:
d

but the listItems variable doesn't contains the link of the table but of the whole html page, and this is pretty weird. I tried different case:
listItems
d.SelectNodes("a") : return null
d.SelectNodes("//a") : return all the link of the page
d.SelectNodes("/a") : return null
what is wrong?
And I would ask also which type of plugin or system did you use for HtmlAgilityPack documentation, is really stunning, thanks.
d.SelectNodes(".//a")
do you want all
href in your listItems?– ershoaib
Aug 8 at 10:53
href
listItems
@ershoaib yep all the href of
odds-data-table– Charanoglu
Aug 8 at 10:53
odds-data-table
1 Answer
1
You have to read Attributes property for each of your HtmlNode from your HtmlNodeCollection like
Attributes
HtmlNode
HtmlNodeCollection
HtmlDocument doc = new HtmlDocument();
var d = doc.GetElementbyId("odds-data-table");
HtmlNodeCollection listItems = d.SelectNodes(".//a");
//This list contains all your href values
List<string> hrefs = new List<string>();
foreach (var item in listItems)
var href = item.Attributes["href"].Value;
hrefs.Add(href);
@Charanoglu, view the answer may it help you :)
– ershoaib
Aug 8 at 11:00
why down vote? please explain?
– ershoaib
Aug 8 at 11:03
it works as expected and gives me a list of hrefs and that OP want
– ershoaib
Aug 8 at 11:04
@Charanoglu, does answer solve your problem?
– ershoaib
Aug 8 at 11:17
@I didn't put the downvote but the problem is that
d.SelectNodes("//a") return the link of the whole page instead of the table– Charanoglu
Aug 8 at 12:16
d.SelectNodes("//a")
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Try
d.SelectNodes(".//a")– Alex K.
Aug 8 at 10:49