0

for example, I have next table

<table>
  <tr>
    <td>
      First
    </td>
    <td>
      1
    </td>
  </tr>
  <tr>
    <td>
      Second
    </td>
    <td>
      2
    </td>
  </tr>
</table>

how can I find element by text, for example "Second" and then get value "2"?

Of course, I can do something like

doc, _ := goquery.NewDocumentFromReader(resp.Body)
caseSize := doc.Find("tr").Each(func(i int, element *goquery.Selection){
  // here I check each element by needed text
})

but maybe there is may be another, more simple way, some specific finder?

Oleh Sobchuk
  • 3,612
  • 2
  • 25
  • 41
  • Put the solution in an answer to the question, and not in your question itself. –  Jul 01 '18 at 16:14

1 Answers1

1

SOLVED

As goQuery uses jQuery finders, I changed goQuery finder in a next way

doc.Find("tr:contains('Second')").Find("td").First().Next().Text()
Oleh Sobchuk
  • 3,612
  • 2
  • 25
  • 41