How to ignore printing when maximum depth limit is reached go colly

WBOY
Release: 2024-02-09 15:45:10
forward
677 people have browsed it

如何忽略打印达到最大深度限制 go colly

php editor Strawberry today introduces a method that can help us ignore the problem of printing reaching the maximum depth limit when using the go colly crawler framework. In the process of crawling web page data, we usually encounter situations where the structure is deeply nested, and the default printing depth limit of the colly framework may not be able to fully display all the data. By setting the debugging options of the colly framework, we can easily solve this problem and obtain a more comprehensive data display. Next, let’s learn about the specific steps!

Question content

I have a go colly crawler and I'm trying to crawl many websites. On my terminal it prints a lot of:

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
Copy after login

This makes it difficult for me to read some of the print I place. I'm wondering if there is any way to ignore printing this in the terminal. Thank you

Solution

Maximum depth limit reached iscolly.errmaxdepth. Your project must have code like this:

c := colly.newcollector(colly.maxdepth(5))

// ...

if err := c.visit("http://go-colly.org/"); err != nil {
    log.println(err)
}
Copy after login

If you don't want this error logged, add a simple check to exclude it:

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)
    }
}
Copy after login

Another option is to redirect the output to a file:

go run . 2>&1 >log.txt
Copy after login

Or use tee to copy the output to a file and to standard output:

go run . 2>&1 | tee log.txt
Copy after login

The above is the detailed content of How to ignore printing when maximum depth limit is reached go colly. For more information, please follow other related articles on the PHP Chinese website!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!