推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
uti6770werty
V2EX  ›  Python

如何屏蔽 pyppeteer 的一些日志输出?

  •  
  •   uti6770werty · Nov 6, 2019 · 4244 views
    This topic created in 2515 days ago, the information mentioned may be changed or developed.

    在爬虫运行过程中,这两句有些影响视觉(多线程的输出)
    想屏蔽它们..
    虽然我已经在:\Python\Python36\Lib\site-packages\pyppeteer\launcher.py
    找到了他们,可以直接注释,但又不太想去改这些内部的东西...

    [I:pyppeteer.launcher] Browser listening on: ws://127.0.0.1:52612/devtools/browser/307c2e2e-c843-4a8f-8ed0-f96fe6242288  
    [I:pyppeteer.launcher] terminate chrome process...  
    

    官网 logging 的说明,以及网上的一些例子,似乎都不太好使,琢磨了一晚,都没能达到效果

                #.......乱写的
                class outFiliter(logging.Filter):
                    def filter(self, record):
                        if record  == "Browser listening on":
                            return False
                        else:
                            return True
    
                f = outFiliter()
                ConsoleHanler.addFilter(f)
                # 将 logger 添加到 handler 里面
                logger.addHandler(ConsoleHanler)
    
    4 replies  •  2019-11-06 23:28:51 +08:00
    Trim21
        1
    Trim21  
       Nov 6, 2019 via iPhone
    record 似乎不是一个 str…我记得好像有个类型来着
    (也可能我吧标准库和跟 loguru 记混了
    gwy15
        2
    gwy15  
       Nov 6, 2019
    Launcher(options={'logLevel': logging.WARNING})
    uti6770werty
        3
    uti6770werty  
    OP
       Nov 6, 2019
    @Trim21 的确不是一个 str,我也不知道是什么,只是例子是这么写的。。。[捂脸]

    @gwy15 我没看懂? 我如果不是直接 import pyppeteer.launcher 的,是其它库调用了它,如 request-html 封装了 pyppeteer.launcher 的调用,那么也不是太合适这么做吧,是不是 logging 本身没办法屏蔽呢?
    Trim21
        4
    Trim21  
       Nov 6, 2019
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   884 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 20:06 · PVG 04:06 · LAX 13:06 · JFK 16:06
    ♥ Do have faith in what you're doing.