C#C
C#3y ago
malkav

❔ ✅ Scrape all <table> </table> elements

I'm trying to use AngleSharp to scrape any url (that is given as parameter) for all table elements on that page's HTML code, and parse the contents into a json.

Here's an example of what I'm trying to achieve:

<table>
  <thead>
    <tr>
      <th scope="col">Header 1</th>
      <th scope="col">Header 2</th>
      <!-- etc -->
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>1</th>
      <td>data</td>
      <!-- etc -->
    </tr>
    <!-- etc -->
  </tbody>
</table>


the json output:
[
  {
    "Header 1": "1",
    "Header 2": "data",
    // etc
  },
  // etc
]

The code I'm trying so far seems to make it hard to reach this actual element, even when trying to use QuerySelectorAll("table")
Was this page helpful?