Pan*_*ko0 3 html go goquery

我在尝试将 HTML 表转换为 Golang 数组时遇到问题。我尝试使用 x/net/html 和 goquery 来实现它,但都没有成功。

假设我们有这个 HTML 表格:

<html>
  <body>
    <table>
      <tr>
        <td>Row 1, Content 1</td>
        <td>Row 1, Content 2</td>
        <td>Row 1, Content 3</td>
        <td>Row 1, Content 4</td>
      </tr>
      <tr>
        <td>Row 2, Content 1</td>
        <td>Row 2, Content 2</td>
        <td>Row 2, Content 3</td>
        <td>Row 2, Content 4</td>
      </tr>
    </table>
  </body>
</html>

我想以这个数组结束:

------------------------------------
|Row 1, Content 1| Row 1, Content 2|
------------------------------------
|Row 2, Content 1| Row 2, Content 2|
------------------------------------

正如你们所看到的,我只是忽略了内容 3 和 4。

我的提取代码:

func extractValue(content []byte) {
  doc, _ := goquery.NewDocumentFromReader(bytes.NewReader(content))

  doc.Find("table tr td").Each(func(i int, td *goquery.Selection) {
    // ...
  })
}
td.NextAll()

但没有运气。你们知道我应该怎么做才能完成它吗?

谢谢。