Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to get all the tables from a website. Then go through all the
XML
<td></td>
nodes.
for some reason the foreach loop gets the same dates from every single loop it goes through.

the HTML looks something like this.
XML
<table>
 <tr> 
<td class=t>1.10</td><td class=t>2.10</td><td class=t>3.10</td><td class=t>4.10</td><td class=t>5.10</td><td class=t>6.10</td>
</tr>
</table>



C#
HtmlNodeCollection weeks = doc.DocumentNode.SelectNodes("//table");
            foreach(HtmlNode week in weeks)
            {
                HtmlNodeCollection tempdate = week.SelectNodes("//td[@class='t']");
                for (int i = 0; i < 6; i++)
                {
                    dates[i] = tempdate[i].InnerText;
                }                
            }
Posted

1 solution

Your logic looks off.
HtmlNodeCollection weeks = doc.DocumentNode.SelectNodes("//table");
            foreach(HtmlNode week in weeks)
            {
                HtmlNodeCollection tempdate = week.SelectNodes("//td[@class='t']");
                for (int i = 0; i < 6; i++)
                {
                    dates[i] = tempdate[i].InnerText;
                }                
            }


In your code, every inner loop you loop through is just resetting the dates[] values when it loops through another HTMLNode (outer loop).

What do you intend to do with dates[]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900