When I use htmlnode to get a webside HTML Like:

<ps-table id="test1" size="medium" class="hydrated"> <div> <table> <thead> <tr> <th>th1</th> </tr> </thead> <tbody> <tr> <td>td1</td> </tr> </tbody> </table> </div> </ps-table> //C# //gethtml var driver UndetectedChromeDriver.Create(driverExecutablePath: await new ChromeDriverInstaller().Auto()); var html = driver.PageSource; static bool GetInnerText(string html) { bool result= false; try{ var td1 = doc.DocumentNode.SelectSingleNode("//ps-table[@id='test1']/div/table/thead/tr[1]/th[1]"); var td2 = doc.DocumentNode.SelectSingleNode("//ps-table[@id='test1']/div/table/tbody/tr[1]/td[1]"); var string1 = td1.InnerText; var string2 = td2.InnerText; } catch { result= false; } return result; }

td1 is correct, but td2 always return null

if td2 only set to tbody like:

doc.DocumentNode.SelectSingleNode("//ps-table[@id='test1']/div/table/tbody");

it's FirstChild = null

I'm Wondering why, has any way to get the tbody's td

Ansel Liou's user avatar

1

What does

var table = doc.DocumentNode.SelectSingleNode("//ps-table[@id='test1']//table"); Console.WriteLine(table?.OuterHtml);

show? Does it have a tbody in there?

If no, then loosen the selector

var tr = doc.DocumentNode.SelectSingleNode("//ps-table[@id='test1']//table//tr[td]");

Is the table written by JS, then you need something like LoadFromBrowser

mplungjan's user avatar

1 Comment

Yes, it have tbody like this: <table><thead><tr></tr></thead><tbody></tbody></table> You can see the tbody always missing the tr section the Html is load from browser Like: var driver UndetectedChromeDriver.Create(driverExecutablePath: await new ChromeDriverInstaller().Auto()); var html = driver.PageSource;

2026-04-17T07:45:59.617Z+00:00

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.