python: 用pyppeteer以无头方式抓取页面

一,安装第三方库:

$ pip install pyppeteer
$ pip install beautifulsoup4

二,代码

import asyncio
from pyppeteer import launch

async def check():
    browser = await launch(executablePath='/usr/bin/google-chrome-stable')
    page = await browser.newPage()
    await page.goto('https://example.com')
    print(await page.title())
    await browser.close()
    
asyncio.run(check()) # 应输出"Example Domain"

 

posted @ 2025-11-16 17:38  刘宏缔的架构森林  阅读(11)  评论(0)    收藏  举报