我有一个go 冷爬虫,我正试图抓取许多网站.在我的终端上,它打印了很多:

2023/05/30 02:22:56 Max depth limit reached
2023/05/30 02:22:56 Max depth limit reached
2023/05/30 02:22:56 Max depth limit reached
2023/05/30 02:22:56 Max depth limit reached
2023/05/30 02:22:56 Max depth limit reached
2023/05/30 02:22:56 Max depth limit reached
2023/05/30 02:22:56 Max depth limit reached

这让我很难阅读我放置的一些 fingerprint .我想知道是否有任何方法可以忽略临时打印这一点.谢谢

推荐答案

Max depth limit reached等于colly.ErrMaxDepth.您的项目中一定有这样的代码:

c := colly.NewCollector(colly.MaxDepth(5))

// ...

if err := c.Visit("http://go-colly.org/"); err != nil {
    log.Println(err)
}

如果您不想记录此错误,请添加一个简单的判断以将其排除:

c := colly.NewCollector(colly.MaxDepth(5))

// ...

if err := c.Visit("http://go-colly.org/"); err != nil {
    // log the error only when the error is not ErrMaxDepth.
    if err != colly.ErrMaxDepth {
        log.Println(err)
    }
}

另一种 Select 是将输出重定向到文件:

go run . 2>&1 >log.txt

或将输出复制到文件,也复制到tee的标准输出:

go run . 2>&1 | tee log.txt

Go相关问答推荐

如何从google.golang.org/grpc/stats包中将golang中不同事件的输出进行组合,以获取func HandlePRC

如何存储来自异步Goroutine的返回值列表?

创建使用逗号而不是加号分隔OU的CSR

Golang中的泛型 struct /接口列表

将DATE类型的SQL字段扫描到GO struct 字段

可以';t从主机连接到ScyllaDB容器

Go-如何在递归函数中关闭通道

如何将Golang测试用例的测试覆盖率值与特定阈值进行比较

使用Goldmark在golang中添加ChildNode会导致堆栈溢出

这是实现超时的常见方法,为什么 time.After 不起作用

hyperledger fabric - go:在 $PATH 中找不到可执行文件

错误!在为 age-viewer-go 运行 wails dev 或 wails build 命令时

使用 Go 解组 SOAP 消息

使用 os/exec 和在命令行执行之间的结果莫名其妙地不同

Golang Getrlimit 返回与 ulimit 不同的值

try 与 golang testify/suite 并行运行测试失败

具有相同提前返回语句的函数的不同基准测试结果

将基本 HTTP AUth 用户/密码凭据存储在 GO 中,无需外部包

comparable和any有什么区别?

是否存在一个Go泛型类型约束,该约束捕获了将类型用作映射中的键的能力?