sbcdp


Namesbcdp JSON
Version 1.1.0 PyPI version JSON
download
home_pagehttps://github.com/ConlinH/sbcdp
SummarySBCDP - Pure CDP (Chrome DevTools Protocol) Automation Framework
upload_time2025-07-11 08:17:13
maintainerNone
docs_urlNone
authorconlin
requires_python>=3.8
licenseMIT
keywords automation cdp chrome devtools browser scraping testing async sync
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# SBCDP - 纯CDP自动化框架

SBCDP - Pure CDP (Chrome DevTools Protocol) Automation Framework

## 项目来源 | Project Origin

SBCDP 是基于 SeleniumBase 项目重构而来的纯CDP自动化框架。提取了SeleniumBase中的CDP功能,并进行了完全重构,创建了一个清晰分离同步和异步操作的现代化自动化框架。

SBCDP is a pure CDP automation framework refactored from the SeleniumBase project. extracted the CDP functionality from SeleniumBase and completely refactored it to create a modern automation framework with clear separation of synchronous and asynchronous operations.

## 安装 | Installation

### 使用pip安装 | Install with pip

```bash
pip install sbcdp
```

### 开发版本安装 | Development Installation

```bash
pip install git+https://github.com/ConlinH/sbcdp
```
或
```bash
git clone https://github.com/ConlinH/sbcdp.git
cd sbcdp
pip install -e .
```

## 快速开始 | Quick Start

### 异步接口 | Asynchronous Interface

```python
import asyncio
from sbcdp import AsyncChrome as Chrome

async def main():
    async with Chrome() as chrome:
        await chrome.get("https://httpbin.org/forms/post")
        await chrome.type('input[name="custname"]', "sbcdp 用户")
        await chrome.type('input[name="custtel"]', "123-456-7890")
        await chrome.type('input[name="custemail"]', "test@cdp-base.com")
        await chrome.type('textarea[name="comments"]', "这是使用sbcdp框架的测试")

        # 选择单选按钮
        await chrome.click('input[value="large"]')
        # 等待元素
        element = await chrome.find_element("button")
        await element.click()
        await chrome.sleep(2)

if __name__ == '__main__':
    asyncio.new_event_loop().run_until_complete(main())
    # asyncio.run(main())
```

### 同步接口 | Synchronous Interface

```python
from sbcdp import SyncChrome as Chrome

with Chrome() as chrome:
    chrome.get("https://httpbin.org/forms/post")
    chrome.type('input[name="custname"]', "sbcdp 用户")
    chrome.type('input[name="custtel"]', "123-456-7890")
    chrome.type('input[name="custemail"]', "test@cdp-base.com")
    chrome.type('textarea[name="comments"]', "这是使用sbcdp框架的测试")

    # 选择单选按钮
    chrome.click('input[value="large"]')
    # 等待元素
    element = chrome.find_element("button")
    element.click()
    chrome.sleep(2)
```

### 5s盾 | cloudflare

```python
import asyncio
from contextlib import suppress

from sbcdp import AsyncChrome as Chrome


async def main():
    # url = "https://fractal-testnet.unisat.io/explorer"
    url = "https://steamdb.info/"
    # url = "https://cn.airbusan.com/content/individual"
    # url = "https://pastebin.com/login"
    # url = "https://simple.ripley.com.pe/"
    # url = "https://www.e-food.gr/"
    async with Chrome() as chrome:
        await chrome.get(url)
        with suppress(Exception):
            await chrome.verify_cf("确认您是真人")
        await chrome.sleep(4)
        assert 'cf_clearance' in {c.name: c.value for c in await chrome.get_all_cookies()}
        print({c.name: c.value for c in await chrome.get_all_cookies()})


if __name__ == "__main__":
    asyncio.new_event_loop().run_until_complete(main())
    # asyncio.run(main())
```

## 核心方法 | Core Methods

### 基础操作 | Basic Operations
- `get(url)` - 导航到URL | Navigate to URL
- `click(selector)` - 点击元素 | Click element
- `type(selector, text)` - 输入文本 | Type text
- `get_text(selector)` - 获取文本 | Get text
- `get_attribute(selector, attr)` - 获取属性 | Get attribute
- `shadow_root_query_selector(selector)` - 查询shadow dom | select shadow dom

### 增强交互 | Enhanced Interaction
- `mouse_click(selector)` - 鼠标点击 | Mouse click
- `press_keys(selector, text)` - 按键输入 | Press keys
- `focus(selector)` - 聚焦元素 | Focus element
- `scroll_to_element(selector)` - 滚动到元素 | Scroll to element

### 视觉效果 | Visual Effects
- `flash(selector)` - 闪烁元素 | Flash element
- `highlight(selector)` - 高亮元素 | Highlight element
- `highlight_overlay(selector)` - 高亮覆盖 | Highlight overlay

### 表单操作 | Form Operations
- `select_option_by_text(selector, text)` - 选择选项 | Select option
- `set_value(selector, value)` - 设置值 | Set value
- `set_text(selector, text)` - 设置文本 | Set text

### 截图功能 | Screenshot Functions
- `save_screenshot(filename)` - 保存页面截图 | Save page screenshot
- `save_element_screenshot(selector, filename)` - 保存元素截图 | Save element screenshot

## 架构设计 | Architecture Design

```
sbcdp/
├── core/           # 核心模块 | Core Modules
│   ├── chrome.py   # Chrome类 | Chrome Class
│   └── methods.py  # 方法实现 | Method Implementation
│   ...
├── driver/         # 驱动模块 | Driver Modules
├── config/         # 配置模块 | Configuration Modules
└── fixtures/       # 工具模块 | Utility Modules
```

## 测试 | Testing

### 运行测试 | Run Tests

```bash
# 运行所有测试 | Run all tests
pytest

# 运行同步测试 | Run sync tests
pytest tests/test_sync_chrome.py

# 运行异步测试 | Run async tests
pytest tests/test_async_chrome.py

# 带覆盖率测试 | Run with coverage
pytest --cov=sbcdp
```

## 许可证 | License

本项目采用 MIT 许可证 - 查看 [LICENSE](LICENSE) 文件了解详情。

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## 致谢 | Acknowledgments

- 感谢 [SeleniumBase](https://github.com/seleniumbase/SeleniumBase) 项目提供的基础代码
- 感谢所有贡献者的努力和支持

- Thanks to the [SeleniumBase](https://github.com/seleniumbase/SeleniumBase) project for providing the foundation code
- Thanks to all contributors for their efforts and support

## 联系方式 | Contact

- 项目主页 | Project Homepage: https://github.com/ConlinH/sbcdp
- 问题反馈 | Issue Tracker: https://github.com/ConlinH/sbcdp/issues
- 邮箱 | Email: 995018884@qq.com

---

**SBCDP - 让自动化更简单、更快速、更可靠!**

**SBCDP - Making automation simpler, faster, and more reliable!**

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ConlinH/sbcdp",
    "name": "sbcdp",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "conlin <995018884@qq.com>",
    "keywords": "automation, cdp, chrome, devtools, browser, scraping, testing, async, sync",
    "author": "conlin",
    "author_email": "conlin <995018884@qq.com>",
    "download_url": "https://files.pythonhosted.org/packages/e9/79/80db3ae662daf526e4842d6172fc1638ecbfab5fe3db89e6f5547d7f336b/sbcdp-1.1.0.tar.gz",
    "platform": null,
    "description": "\r\n# SBCDP - \u7eafCDP\u81ea\u52a8\u5316\u6846\u67b6\r\n\r\nSBCDP - Pure CDP (Chrome DevTools Protocol) Automation Framework\r\n\r\n## \u9879\u76ee\u6765\u6e90 | Project Origin\r\n\r\nSBCDP \u662f\u57fa\u4e8e SeleniumBase \u9879\u76ee\u91cd\u6784\u800c\u6765\u7684\u7eafCDP\u81ea\u52a8\u5316\u6846\u67b6\u3002\u63d0\u53d6\u4e86SeleniumBase\u4e2d\u7684CDP\u529f\u80fd\uff0c\u5e76\u8fdb\u884c\u4e86\u5b8c\u5168\u91cd\u6784\uff0c\u521b\u5efa\u4e86\u4e00\u4e2a\u6e05\u6670\u5206\u79bb\u540c\u6b65\u548c\u5f02\u6b65\u64cd\u4f5c\u7684\u73b0\u4ee3\u5316\u81ea\u52a8\u5316\u6846\u67b6\u3002\r\n\r\nSBCDP is a pure CDP automation framework refactored from the SeleniumBase project. extracted the CDP functionality from SeleniumBase and completely refactored it to create a modern automation framework with clear separation of synchronous and asynchronous operations.\r\n\r\n## \u5b89\u88c5 | Installation\r\n\r\n### \u4f7f\u7528pip\u5b89\u88c5 | Install with pip\r\n\r\n```bash\r\npip install sbcdp\r\n```\r\n\r\n### \u5f00\u53d1\u7248\u672c\u5b89\u88c5 | Development Installation\r\n\r\n```bash\r\npip install git+https://github.com/ConlinH/sbcdp\r\n```\r\n\u6216\r\n```bash\r\ngit clone https://github.com/ConlinH/sbcdp.git\r\ncd sbcdp\r\npip install -e .\r\n```\r\n\r\n## \u5feb\u901f\u5f00\u59cb | Quick Start\r\n\r\n### \u5f02\u6b65\u63a5\u53e3 | Asynchronous Interface\r\n\r\n```python\r\nimport asyncio\r\nfrom sbcdp import AsyncChrome as Chrome\r\n\r\nasync def main():\r\n    async with Chrome() as chrome:\r\n        await chrome.get(\"https://httpbin.org/forms/post\")\r\n        await chrome.type('input[name=\"custname\"]', \"sbcdp \u7528\u6237\")\r\n        await chrome.type('input[name=\"custtel\"]', \"123-456-7890\")\r\n        await chrome.type('input[name=\"custemail\"]', \"test@cdp-base.com\")\r\n        await chrome.type('textarea[name=\"comments\"]', \"\u8fd9\u662f\u4f7f\u7528sbcdp\u6846\u67b6\u7684\u6d4b\u8bd5\")\r\n\r\n        # \u9009\u62e9\u5355\u9009\u6309\u94ae\r\n        await chrome.click('input[value=\"large\"]')\r\n        # \u7b49\u5f85\u5143\u7d20\r\n        element = await chrome.find_element(\"button\")\r\n        await element.click()\r\n        await chrome.sleep(2)\r\n\r\nif __name__ == '__main__':\r\n    asyncio.new_event_loop().run_until_complete(main())\r\n    # asyncio.run(main())\r\n```\r\n\r\n### \u540c\u6b65\u63a5\u53e3 | Synchronous Interface\r\n\r\n```python\r\nfrom sbcdp import SyncChrome as Chrome\r\n\r\nwith Chrome() as chrome:\r\n    chrome.get(\"https://httpbin.org/forms/post\")\r\n    chrome.type('input[name=\"custname\"]', \"sbcdp \u7528\u6237\")\r\n    chrome.type('input[name=\"custtel\"]', \"123-456-7890\")\r\n    chrome.type('input[name=\"custemail\"]', \"test@cdp-base.com\")\r\n    chrome.type('textarea[name=\"comments\"]', \"\u8fd9\u662f\u4f7f\u7528sbcdp\u6846\u67b6\u7684\u6d4b\u8bd5\")\r\n\r\n    # \u9009\u62e9\u5355\u9009\u6309\u94ae\r\n    chrome.click('input[value=\"large\"]')\r\n    # \u7b49\u5f85\u5143\u7d20\r\n    element = chrome.find_element(\"button\")\r\n    element.click()\r\n    chrome.sleep(2)\r\n```\r\n\r\n### 5s\u76fe | cloudflare\r\n\r\n```python\r\nimport asyncio\r\nfrom contextlib import suppress\r\n\r\nfrom sbcdp import AsyncChrome as Chrome\r\n\r\n\r\nasync def main():\r\n    # url = \"https://fractal-testnet.unisat.io/explorer\"\r\n    url = \"https://steamdb.info/\"\r\n    # url = \"https://cn.airbusan.com/content/individual\"\r\n    # url = \"https://pastebin.com/login\"\r\n    # url = \"https://simple.ripley.com.pe/\"\r\n    # url = \"https://www.e-food.gr/\"\r\n    async with Chrome() as chrome:\r\n        await chrome.get(url)\r\n        with suppress(Exception):\r\n            await chrome.verify_cf(\"\u786e\u8ba4\u60a8\u662f\u771f\u4eba\")\r\n        await chrome.sleep(4)\r\n        assert 'cf_clearance' in {c.name: c.value for c in await chrome.get_all_cookies()}\r\n        print({c.name: c.value for c in await chrome.get_all_cookies()})\r\n\r\n\r\nif __name__ == \"__main__\":\r\n    asyncio.new_event_loop().run_until_complete(main())\r\n    # asyncio.run(main())\r\n```\r\n\r\n## \u6838\u5fc3\u65b9\u6cd5 | Core Methods\r\n\r\n### \u57fa\u7840\u64cd\u4f5c | Basic Operations\r\n- `get(url)` - \u5bfc\u822a\u5230URL | Navigate to URL\r\n- `click(selector)` - \u70b9\u51fb\u5143\u7d20 | Click element\r\n- `type(selector, text)` - \u8f93\u5165\u6587\u672c | Type text\r\n- `get_text(selector)` - \u83b7\u53d6\u6587\u672c | Get text\r\n- `get_attribute(selector, attr)` - \u83b7\u53d6\u5c5e\u6027 | Get attribute\r\n- `shadow_root_query_selector(selector)` - \u67e5\u8be2shadow dom | select shadow dom\r\n\r\n### \u589e\u5f3a\u4ea4\u4e92 | Enhanced Interaction\r\n- `mouse_click(selector)` - \u9f20\u6807\u70b9\u51fb | Mouse click\r\n- `press_keys(selector, text)` - \u6309\u952e\u8f93\u5165 | Press keys\r\n- `focus(selector)` - \u805a\u7126\u5143\u7d20 | Focus element\r\n- `scroll_to_element(selector)` - \u6eda\u52a8\u5230\u5143\u7d20 | Scroll to element\r\n\r\n### \u89c6\u89c9\u6548\u679c | Visual Effects\r\n- `flash(selector)` - \u95ea\u70c1\u5143\u7d20 | Flash element\r\n- `highlight(selector)` - \u9ad8\u4eae\u5143\u7d20 | Highlight element\r\n- `highlight_overlay(selector)` - \u9ad8\u4eae\u8986\u76d6 | Highlight overlay\r\n\r\n### \u8868\u5355\u64cd\u4f5c | Form Operations\r\n- `select_option_by_text(selector, text)` - \u9009\u62e9\u9009\u9879 | Select option\r\n- `set_value(selector, value)` - \u8bbe\u7f6e\u503c | Set value\r\n- `set_text(selector, text)` - \u8bbe\u7f6e\u6587\u672c | Set text\r\n\r\n### \u622a\u56fe\u529f\u80fd | Screenshot Functions\r\n- `save_screenshot(filename)` - \u4fdd\u5b58\u9875\u9762\u622a\u56fe | Save page screenshot\r\n- `save_element_screenshot(selector, filename)` - \u4fdd\u5b58\u5143\u7d20\u622a\u56fe | Save element screenshot\r\n\r\n## \u67b6\u6784\u8bbe\u8ba1 | Architecture Design\r\n\r\n```\r\nsbcdp/\r\n\u251c\u2500\u2500 core/           # \u6838\u5fc3\u6a21\u5757 | Core Modules\r\n\u2502   \u251c\u2500\u2500 chrome.py   # Chrome\u7c7b | Chrome Class\r\n\u2502   \u2514\u2500\u2500 methods.py  # \u65b9\u6cd5\u5b9e\u73b0 | Method Implementation\r\n\u2502   ...\r\n\u251c\u2500\u2500 driver/         # \u9a71\u52a8\u6a21\u5757 | Driver Modules\r\n\u251c\u2500\u2500 config/         # \u914d\u7f6e\u6a21\u5757 | Configuration Modules\r\n\u2514\u2500\u2500 fixtures/       # \u5de5\u5177\u6a21\u5757 | Utility Modules\r\n```\r\n\r\n## \u6d4b\u8bd5 | Testing\r\n\r\n### \u8fd0\u884c\u6d4b\u8bd5 | Run Tests\r\n\r\n```bash\r\n# \u8fd0\u884c\u6240\u6709\u6d4b\u8bd5 | Run all tests\r\npytest\r\n\r\n# \u8fd0\u884c\u540c\u6b65\u6d4b\u8bd5 | Run sync tests\r\npytest tests/test_sync_chrome.py\r\n\r\n# \u8fd0\u884c\u5f02\u6b65\u6d4b\u8bd5 | Run async tests\r\npytest tests/test_async_chrome.py\r\n\r\n# \u5e26\u8986\u76d6\u7387\u6d4b\u8bd5 | Run with coverage\r\npytest --cov=sbcdp\r\n```\r\n\r\n## \u8bb8\u53ef\u8bc1 | License\r\n\r\n\u672c\u9879\u76ee\u91c7\u7528 MIT \u8bb8\u53ef\u8bc1 - \u67e5\u770b [LICENSE](LICENSE) \u6587\u4ef6\u4e86\u89e3\u8be6\u60c5\u3002\r\n\r\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\r\n\r\n## \u81f4\u8c22 | Acknowledgments\r\n\r\n- \u611f\u8c22 [SeleniumBase](https://github.com/seleniumbase/SeleniumBase) \u9879\u76ee\u63d0\u4f9b\u7684\u57fa\u7840\u4ee3\u7801\r\n- \u611f\u8c22\u6240\u6709\u8d21\u732e\u8005\u7684\u52aa\u529b\u548c\u652f\u6301\r\n\r\n- Thanks to the [SeleniumBase](https://github.com/seleniumbase/SeleniumBase) project for providing the foundation code\r\n- Thanks to all contributors for their efforts and support\r\n\r\n## \u8054\u7cfb\u65b9\u5f0f | Contact\r\n\r\n- \u9879\u76ee\u4e3b\u9875 | Project Homepage: https://github.com/ConlinH/sbcdp\r\n- \u95ee\u9898\u53cd\u9988 | Issue Tracker: https://github.com/ConlinH/sbcdp/issues\r\n- \u90ae\u7bb1 | Email: 995018884@qq.com\r\n\r\n---\r\n\r\n**SBCDP - \u8ba9\u81ea\u52a8\u5316\u66f4\u7b80\u5355\u3001\u66f4\u5feb\u901f\u3001\u66f4\u53ef\u9760\uff01**\r\n\r\n**SBCDP - Making automation simpler, faster, and more reliable!**\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "SBCDP - Pure CDP (Chrome DevTools Protocol) Automation Framework",
    "version": "1.1.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/ConlinH/sbcdp/issues",
        "Documentation": "https://github.com/ConlinH/sbcdp#readme",
        "Homepage": "https://github.com/ConlinH/sbcdp",
        "Repository": "https://github.com/ConlinH/sbcdp",
        "Source": "https://github.com/ConlinH/sbcdp"
    },
    "split_keywords": [
        "automation",
        " cdp",
        " chrome",
        " devtools",
        " browser",
        " scraping",
        " testing",
        " async",
        " sync"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bc8bad28579032052566ebd0230e3ac7025e796ec668fa673e536453951f2b34",
                "md5": "d67efcf06ce0e1a95b37e55331a3bb54",
                "sha256": "98a3bb39c80eef6ca1e6ee1de0fa00966c06c9f192a62c693e9c92bd5d1bfe15"
            },
            "downloads": -1,
            "filename": "sbcdp-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d67efcf06ce0e1a95b37e55331a3bb54",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 94506,
            "upload_time": "2025-07-11T08:17:11",
            "upload_time_iso_8601": "2025-07-11T08:17:11.027854Z",
            "url": "https://files.pythonhosted.org/packages/bc/8b/ad28579032052566ebd0230e3ac7025e796ec668fa673e536453951f2b34/sbcdp-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e97980db3ae662daf526e4842d6172fc1638ecbfab5fe3db89e6f5547d7f336b",
                "md5": "3449dcfdc2ffcd9b715b45d078d5f21c",
                "sha256": "1f41c3d0976e4004c4d4ecca0a9aee5bb0c3eadc993d4209495343f53454df58"
            },
            "downloads": -1,
            "filename": "sbcdp-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "3449dcfdc2ffcd9b715b45d078d5f21c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 96135,
            "upload_time": "2025-07-11T08:17:13",
            "upload_time_iso_8601": "2025-07-11T08:17:13.149360Z",
            "url": "https://files.pythonhosted.org/packages/e9/79/80db3ae662daf526e4842d6172fc1638ecbfab5fe3db89e6f5547d7f336b/sbcdp-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-11 08:17:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ConlinH",
    "github_project": "sbcdp",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "sbcdp"
}
        
Elapsed time: 1.04322s