python-3.x - 如何在 Pyppeteer 中禁用图像/CSS?

标签 python-3.x puppeteer pyppeteer

如何在 Puppeteer 中禁用图像/CSS?
我看过这个教程 https://www.scrapehero.com/how-to-increase-web-scraping-speed-using-puppeteer/
但我不知道如何将其翻译成 Python

最佳答案

基于来自 https://github.com/miyakogi/pyppeteer/blob/dev/pyppeteer/page.py#L312 的示例:

await page.setRequestInterception(True)
async def intercept(request):
    if any(request.resourceType == _ for _ in ('stylesheet', 'image', 'font')):
        await request.abort()
    else:
        await request.continue_()
page.on('request', lambda req: asyncio.ensure_future(intercept(req)))

关于python-3.x - 如何在 Pyppeteer 中禁用图像/CSS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59471331/

相关文章:

python - 将混合数据类型字典中的 float 转换为 int

node.js - Puppeteer 无法抓取动态生成的内容

puppeteer - pyppeteer 等待页面的所有元素加载完毕

python - 在 Python 中创建新的转换说明符

python - 严格增加列表中相邻元素之间的差异

django - 使用 Django 发送文件时出错 - 文件结果为空

python - 使用 pyppeteer 与 asyncio 关联来抓取内容

node.js - 使用 Node.js 中的 async/await 函数限制从 CSV 文件读取的行数

javascript - Puppeteer 中的 jsHandle 和 elementHandle 有什么区别?

python - 使用 pyppeteer 创建 for 循环的理想方法