puppeteer-table-parser icon indicating copy to clipboard operation
puppeteer-table-parser copied to clipboard

Cannot parse header and one column contain DOM elements.

Open TimKieu opened this issue 1 year ago • 2 comments

Please help. I am crawling a table which its header and one column contain DOM elements, not plain text as the examples. The error mentions about settings and conversion exception on those.

TimKieu avatar Aug 27 '24 08:08 TimKieu

Can I see such HTML Table so I can debug it?

Tomas2D avatar Aug 29 '24 16:08 Tomas2D

If your table looks like this

<table id="table-overview">
  <thead>
  <tr>
    <th>A</th>
    <th><input type="checkbox" checked></th>
    <th>C</th>
  </tr>
  </thead>
  <tbody>
  <tr>
    <td>A1</td>
    <td>B1</td>
    <td><img src='#' alt='image'>C1</td>
  </tr>
  <tr>
    <td><a href='#'>A1</a></td>
    <td><input type="checkbox" checked></td>
    <td>C1</td>
  </tr>
  </tbody>
</table>

Then you can do this

    const data = await tableParser(page, {
      selector: '#table-overview',
      asArray: false,
      allowedColNames: {
        'A': 'A',
        '': 'B',
        'C': 'C',
      }
    });

Tomas2D avatar Sep 14 '24 10:09 Tomas2D