如何突破goquery Go中的每个循环
How to break out goquery Each loop in Go
你能帮我打出一个goquery Each looping的循环吗?
我使用了 "return" 但它没有跳出循环,只是通过迭代...
如何在以下代码中打破 Each 循环:
doc.Find("td").Each(func(i int, s *goquery.Selection) {
summary := s.Text()
if summary == "--" {
//I want to break the Each loop here
}
}
使用EachWithBreak
方法
doc.Find("td").EachWithBreak(func(i int, s *goquery.Selection) bool {
summary := s.Text()
if summary == "--" {
return false
}
return true
})
在 goquery 1.7.1 iteration.go 中,它说:
It is identical to Each except that it is possible to break out of the loop by returning false in the callback function.
所以你需要 return false 来打破循环。
你能帮我打出一个goquery Each looping的循环吗? 我使用了 "return" 但它没有跳出循环,只是通过迭代... 如何在以下代码中打破 Each 循环:
doc.Find("td").Each(func(i int, s *goquery.Selection) {
summary := s.Text()
if summary == "--" {
//I want to break the Each loop here
}
}
使用EachWithBreak
方法
doc.Find("td").EachWithBreak(func(i int, s *goquery.Selection) bool {
summary := s.Text()
if summary == "--" {
return false
}
return true
})
在 goquery 1.7.1 iteration.go 中,它说:
It is identical to Each except that it is possible to break out of the loop by returning false in the callback function.
所以你需要 return false 来打破循环。