Skip to main content

一个使用pyppeteer进行渲染的请求库

Project description

这是一个使用pyppeteer对指定的请求url进行渲染的库


快速开始

from smawe_pyppeteer.utils.smawe_pyppeteer import get
import asyncio

if __name__ == '__main__':
    from pathlib import Path


    async def main():
        script = "document.cookie"
        r = await get(
            "http://www.fangdi.com.cn/index.html", auto_close=True, headless=False, delay=5, pretend=True,
            user_data_dir=Path("test").resolve(),
            args=[], script=script, callable=handle,
            enabled_interception=True, enabled_maximize=False
        )
        print(r.text)
        print(r.request)
        print(r.status)
        print(r.script_result)


    async def handle(request):
        print(request.url)
        await request.continue_()


    asyncio.get_event_loop().run_until_complete(main())

参数解释

async def get( url, delay=None, wait_for=None, page_width=None, page_height=None, enabled_interception=None, script=None, callable=None, **kwargs ):
  使用pyppeteer对指定url进行渲染
    :param url: url
    :param wait_for: css选择器或者xpath, 等待指定的元素出现在页面上
    :param delay: 打开指定url后要等待的秒数, 默认为None不进行等待(同时指定了delay和wait_for,则先delay,然后再wait_for)
    :param page_width: 页面宽度
    :param page_height: 页面高度
    :param enabled_interception: 是否启用请求拦截
    :param callable: 启动了请求拦截后要调用的协程函数, 它接受单个request参数, 未提供则使用默认实现.
    :param script: js表达式/js函数, 脚本在最后才执行, 即page关闭前执行. 结果可通过PyppeteerResponse.script_result属性获取.
    :param kwargs:
        headless(bool): 是否启动无头模式, 默认是True.(启用了此参数(参数被设置为True时), auto_close被强制设为True)
        path(str): 要运行的 Chromium 或 Chrome 可执行文件的路径.
        auto_close(bool): 脚本完成后自动关闭浏览器进程. 默认为 True.
        window_width(str): 浏览器窗口宽度, 以像素为单位.注意window_width和window_height必须同时设置, 否则会不生效
        window_height(str): 浏览器窗口高度, 以像素为单位.注意window_width和window_height必须同时设置, 否则会不生效
        args(list[str]): 传递给浏览器进程的附加参数.
        enabled_maximize(bool): 是否启用窗口最大化, 默认为True, 如果同时指定了注意window_width和window_height, 此参数不会生效
    :return: PyppeteerResponse


包源码中已经有参数解释了, 可自行查看

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smawe_pyppeteer-0.0.1.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

smawe_pyppeteer-0.0.1-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file smawe_pyppeteer-0.0.1.tar.gz.

File metadata

  • Download URL: smawe_pyppeteer-0.0.1.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.7

File hashes

Hashes for smawe_pyppeteer-0.0.1.tar.gz
Algorithm Hash digest
SHA256 5884ab17f808d9307cf80f09d67fd06028c865198679e01975e2a0f92586f763
MD5 b54d18077f784aca7d7cefcbbd70c239
BLAKE2b-256 7c369c0cc1bbb55d7b2f38bd3bd7f2b5f82714ec2d6958bb6a0ec9a69d945858

See more details on using hashes here.

File details

Details for the file smawe_pyppeteer-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for smawe_pyppeteer-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2be824694741b68df7cef11d46a7075d2a965dfb535bdb4dc15d025f85538022
MD5 ba2a0e0d3a645dff26cc738be597a93a
BLAKE2b-256 a2e42e1e0d7ef570c17343b3ed0b5e0e2bd6299c3904519a64ab0b2067f226ca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page