异步拆分包装器python库
aiosplinter的Python项目详细描述
aiospinter-异步拆分包装器python库
异步splinter包装器python库
安装
要从PyPI安装,请运行:
$ pip install aiosplinter
用法
请参阅splinter
documentation,因为aiosplinter
使用与
splinter
有两个例外:
- 所有函数都转换为协程,这意味着您必须在所有函数调用之前添加
await
关键字。 - 要从
aiosplinter
异步创建类,请使用静态方法create
。
示例(使用chrome
打开https://google.com,制作屏幕截图并在默认浏览器中显示):
#!/usr/bin/env pythonimportasyncioimportwebbrowserfrompathlibimportPathimportaiosplinterbrowser_name='chrome'browser=asyncio.run(aiosplinter.Browser(driver_name=browser_name))url='https://google.com'asyncio.run(browser.visit(url=url))screenshot_filename_base=str(Path('~/google.com_screenshot_').expanduser())screenshot_filename=asyncio.run(browser.screenshot(name=screenshot_filename_base,full=True))webbrowser.open(url=f'file://{screenshot_filename}')asyncio.run(browser.quit())