最新消息:20190717 VPS服务器:Vultr新加坡,WordPress主题:大前端D8,统一介绍入口:关于

【已解决】pyppeteer功能正常但是没有启动Chrome浏览器

浏览器 crifan 18浏览 0评论
折腾:
【未解决】Mac中初始化搭建Python版puppeteer的pyppeteer的开发环境
期间,Python版本的puppeteer:pyppeteer,虽然功能正常了,但是没有启动浏览器
为何没有启动 可视化的 Chrome浏览器。
否则,如何查看元素的html,后续如何定位元素?
puppeteer not launching chrome
node.js – Puppeteer not launching chromium in Mac 10.14 – Stack Overflow
“Puppeteer launches Chromium in headless mode. To launch a full version of Chromium, set the ‘headless’ option when launching a browser:”
要加上:headless: false ?
GitHub – puppeteer/puppeteer: Headless Chrome Node.js API
javascript – Node JS Puppeteer headful Browser doesnt launch – Stack Overflow
https://stackoverflow.com/questions/61539987/node-js-puppeteer-headful-browser-doesnt-launch
node.js – Puppeteer not running in headless:false mode – Stack Overflow
node.js – Puppeteer is failing to launch the browser in local – Stack Overflow
pdf generation – Failed to launch chrome! spawn …node_modules/puppeteer/…/chrome ENOENT TROUBLESHOOTING when using Puppeteer – Stack Overflow
通过:
browser = await launch()
查看到源码:
/Users/crifan/.pyenv/versions/3.6.6/lib/python3.6/site-packages/pyppeteer/launcher.py
async def launch(options: dict = None, **kwargs: Any) -> Browser:
    """Start chrome process and return :class:`~pyppeteer.browser.Browser`.
    This function is a shortcut to :meth:`Launcher(options, **kwargs).launch`.
    Available options are:
    * ``ignoreHTTPSErrors`` (bool): Whether to ignore HTTPS errors. Defaults to
      ``False``.
    * ``headless`` (bool): Whether to run browser in headless mode. Defaults to
      ``True`` unless ``appMode`` or ``devtools`` options is ``True``.
    * ``executablePath`` (str): Path to a Chromium or Chrome executable to run
      instead of default bundled Chromium.
    * ``slowMo`` (int|float): Slow down pyppeteer operations by the specified
      amount of milliseconds.
    * ``defaultViewport`` (dict): Set a consistent viewport for each page.
      Defaults to an 800x600 viewport. ``None`` disables default viewport.
      * ``width`` (int): page width in pixels.
      * ``height`` (int): page height in pixels.
      * ``deviceScaleFactor`` (int|float): Specify device scale factor (can be
        thought as dpr). Defaults to ``1``.
      * ``isMobile`` (bool): Whether the ``meta viewport`` tag is taken into
        account. Defaults to ``False``.
      * ``hasTouch`` (bool): Specify if viewport supports touch events.
        Defaults to ``False``.
      * ``isLandscape`` (bool): Specify if viewport is in landscape mode.
        Defaults to ``False``.
    * ``args`` (List[str]): Additional arguments (flags) to pass to the browser
      process.
    * ``ignoreDefaultArgs`` (bool or List[str]): If ``True``, do not use
      :func:`~pyppeteer.defaultArgs`. If list is given, then filter out given
      default arguments. Dangerous option; use with care. Defaults to
      ``False``.
    * ``handleSIGINT`` (bool): Close the browser process on Ctrl+C. Defaults to
      ``True``.
    * ``handleSIGTERM`` (bool): Close the browser process on SIGTERM. Defaults
      to ``True``.
    * ``handleSIGHUP`` (bool): Close the browser process on SIGHUP. Defaults to
      ``True``.
    * ``dumpio`` (bool): Whether to pipe the browser process stdout and stderr
      into ``process.stdout`` and ``process.stderr``. Defaults to ``False``.
    * ``userDataDir`` (str): Path to a user data directory.
    * ``env`` (dict): Specify environment variables that will be visible to the
      browser. Defaults to same as python process.
    * ``devtools`` (bool): Whether to auto-open a DevTools panel for each tab.
      If this option is ``True``, the ``headless`` option will be set
      ``False``.
    * ``logLevel`` (int|str): Log level to print logs. Defaults to same as the
      root logger.
    * ``autoClose`` (bool): Automatically close browser process when script
      completed. Defaults to ``True``.
    * ``loop`` (asyncio.AbstractEventLoop): Event loop (**experimental**).
    * ``appMode`` (bool): Deprecated.
    This function combines 3 steps:
    1. Infer a set of flags to launch chromium with using
       :func:`~pyppeteer.defaultArgs`.
    2. Launch browser and start managing its process according to the
       ``executablePath``, ``handleSIGINT``, ``dumpio``, and other options.
    3. Create an instance of :class:`~pyppeteer.browser.Browser` class and
       initialize it with ``defaultViewport``, ``slowMo``, and
       ``ignoreHTTPSErrors``.
    ``ignoreDefaultArgs`` option can be used to customize behavior on the (1)
    step. For example, to filter out ``--mute-audio`` from default arguments:
    .. code::
        browser = await launch(ignoreDefaultArgs=['--mute-audio'])
    .. note::
        Pyppeteer can also be used to control the Chrome browser, but it works
        best with the version of Chromium it is bundled with. There is no
        guarantee it will work with any other version. Use ``executablePath``
        option with extreme caution.
    """
    return await Launcher(options, **kwargs).launch()
其中就有参数:
“* “headless“ (bool): Whether to run browser in headless mode. Defaults to
      “True“ unless “appMode“ or “devtools“ options is “True“.”
本来以为官网教程:
Pyppeteer’s documentation — Pyppeteer 0.0.25 documentation
没有launch的参数介绍呢
后来看到有:
Keyword arguments for options
既支持 dict传参:
browser =awaitlaunch({'headless': True})
也支持(更加Pythonic方式的)key=value传参:
browser = await launch(headless=True)
去试试
browser = await launch(headless=True)
结果:
仍没开启浏览器
不过注意到了:Mac的Dock中,动了一下,好像是:
想要启动Chrome,但是没启动起来
搞错了,应该传入
browser = await launch(headless=False)
结果:
就可以了启动浏览器Chromium了:
【总结】
此处,puppeteer(pyppeteer)默认是启动 无头模式
即:
browser = await launch(headless=True)
想要启动(Chromium)浏览器,可以指定 不用无头模式:
browser = await launch(headless=False)
即可。

另外:
也可以写成dict字典的方式传参:
browser = await launch({'headless': False})

转载请注明:在路上 » 【已解决】pyppeteer功能正常但是没有启动Chrome浏览器

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
16 queries in 0.079 seconds, using 9.32MB memory