html-agility-pack
html-agility-pack copied to clipboard
tbody missing
I am trying to read an Html and there is a table with thead but no tbody. Is there any way to add tbody using the htmlagility pack?
There is currently no way to force a tbody.
It could be possible to add it by creating a node but I'm not sure that's what you are looking for.
Chorme or Edge will add tbody automatically.
tbody is implied if there is none, it says so in the spec:
A start tag whose tag name is one of: "td", "th", "tr"
Clear the stack back to a table context. (See below.)
Insert an HTML element for a "tbody" start tag token with no attributes, then switch the insertion mode to "in table body".
Reprocess the current token.
This issue has been around for a bit but hopefully this will help others that run into the same thing.
I ran into a similar issue where I was using chrome to generate an xpath for me and it was including the tbody that chrome inserted but did not exist in my source. In my case I was able to work around this by slightly altering the xpath to omit the tbody.
So if chrome devtools gave me "/html/body/table/tbody/tr[2]/td[1]" I would just change it to "/html/body/table//tr[2]/td[1]" (note the // instead of /tbody/). This would let my xpath selectors work