Reputation: 3
The problem I am facing is to use SelectNode and scrape a table from the internet and put it into a DataGridView. My code works almost the way I want it but I get all "th" together instead of seperatly. An exmaple would be:
<th>1hello world<th>
<th>!<th>
<th>How was your day<th>
The result I then get is (which is in one long string):
Hello world ! How was your day
instead it should be (under the descendant should be separated in a new column and when finished go to a new row):
Hello world
!
How was your day
The code SelectNode that works and where I have tried to change and manipulate:
var table = doc.DocumentNode.SelectSingleNode(".//div[@id=\"cr_cashflow\"]/div[2]/div/table")
.Descendants("tr")
.Select(th => th.InnerText.Trim())
.ToList();
foreach (var tables in table)
{
dt1.Rows.Add(new object[] { tables.ToString() });
}
dataGridView1.DataSource= dt;
From my understanding .Select is that part where the code adds all "th" together. I have therefore tried to add additional Select, Descendants etc. but without success. Is there some code I can add to either separate each (in the table it´s the seperate cells) or add a split so each is in a different column and that the next starts from a new row?
Edit: First 2 rows is what I want to get out and the last 2 rows is what I get
More detailed picture of result
Upvotes: 0
Views: 45