gpt4 book ai didi

go - 我如何在Go中过滤此输出

转载 作者:行者123 更新时间:2023-12-01 22:13:16 25 4
gpt4 key购买 nike

我正在尝试过滤此的终端输出,但是我不确定如何执行此操作。我尝试将输出放入 slice 中,但是它们输出单独的 slice ,而且我不确定如何将这些 slice 连接在一起以构成一个 slice 。在搜索过滤输出时,我发现没有任何帮助,因此我希望有人可以给我解决方案。我想获取//abs.twimg.com

func main() {
profileURL := "url"
resp, err := soup.Get(profileURL)
check("Couldn't send GET request:", err)

parse := soup.HTMLParse(resp)

find := parse.Find("head").FindAll("link")
for _, i := range find {
links := []string{i.Attrs()["href"]}
log.Println(links)
}
}

输出:
2020/06/09 08:54:55 [//abs.twimg.com  ]
2020/06/09 08:54:55 [//api.twitter.com ]
2020/06/09 08:54:55 [//pbs.twimg.com ]
2020/06/09 08:54:55 [//t.co ]
2020/06/09 08:54:55 [//video.twimg.com ]
2020/06/09 08:54:55 [//abs.twimg.com ]
2020/06/09 08:54:55 [//api.twitter.com ]
2020/06/09 08:54:55 [//pbs.twimg.com ]
2020/06/09 08:54:55 [//t.co ]
2020/06/09 08:54:55 [//video.twimg.com ]
2020/06/09 08:54:55 [https://abs.twimg.com/responsive-web/web/polyfills.604422d4.js ]
2020/06/09 08:54:55 [https://abs.twimg.com/responsive-web/web/vendors~main.55bd4704.js ]
2020/06/09 08:54:55 [https://abs.twimg.com/responsive-web/web/i18n-rweb/en.15808594.js ]
2020/06/09 08:54:55 [https://abs.twimg.com/responsive-web/web/i18n-horizon/en.d212af84.js ]
2020/06/09 08:54:55 [https://abs.twimg.com/responsive-web/web/main.cc767dc4.js ]
2020/06/09 08:54:55 [/manifest.json ]

最佳答案

我希望这有帮助!

import (
"log"
"strings"
)

func main() {
profileURL := "url"
resp, err := soup.Get(profileURL)
check("Couldn't send GET request:", err)

parse := soup.HTMLParse(resp)

find := parse.Find("head").FindAll("link")
filter := make([]string, 0)
for _, i := range find {
// map[string]string
if strings.Contains(i.Attrs()["href"], "//abs.twimg.com") {
filter = append(filter, i.Attrs()["href"])
}
}
log.Println(filter)
}

关于go - 我如何在Go中过滤此输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62277932/

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