gpt4 book ai didi

go - 如何突破goquery Go中的每个循环

转载 作者:IT王子 更新时间:2023-10-29 01:09:58 24 4
gpt4 key购买 nike

你能帮我打出一个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
})

关于go - 如何突破goquery Go中的每个循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37189426/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com