html-agility-pack icon indicating copy to clipboard operation
html-agility-pack copied to clipboard

tbody missing

Open miho99 opened this issue 7 years ago • 4 comments

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?

miho99 avatar Jul 30 '18 07:07 miho99

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.

JonathanMagnan avatar Jul 31 '18 12:07 JonathanMagnan

Chorme or Edge will add tbody automatically.

LuohuaRain avatar Aug 22 '18 05:08 LuohuaRain

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.

poizan42 avatar Feb 21 '19 17:02 poizan42

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

SEGEEK avatar Jul 17 '20 21:07 SEGEEK