Skip to main content

一个基于python的网页自动化工具,可以同时控制多个浏览器,无需为不同版本的浏览器下载不同的驱动。

Project description

DPClone

一个基于Python的网页自动化工具,可以同时控制多个浏览器,无需为不同版本的浏览器下载不同的驱动。

特性

  • 🚀 无需驱动: 直接控制浏览器,无需下载和管理驱动程序
  • 🔄 双模式: 支持浏览器控制模式和requests模式
  • 🎯 简单易用: 简洁的API设计,易于学习和使用
  • 🔧 功能丰富: 支持元素查找、点击、输入、截图等常用操作
  • 📱 多浏览器: 支持Chrome、Edge等Chromium内核浏览器
  • 🛡️ 稳定可靠: 内置重试机制和异常处理

安装

pip install dpclone

快速开始

浏览器模式

from dpclone import ChromiumPage

# 创建页面对象
page = ChromiumPage()

# 访问网页
page.get('https://www.example.com')

# 查找元素并操作
element = page.ele('#search-input')
element.input('搜索内容')

# 点击按钮
page.ele('#search-button').click()

# 获取文本
text = page.ele('.result').text
print(text)

Session模式

from dpclone import SessionPage

# 创建会话对象
session = SessionPage()

# 发送请求
session.get('https://api.example.com/data')

# 解析响应
data = session.json
print(data)

混合模式

from dpclone import WebPage

# 创建混合模式页面对象
page = WebPage()

# 可以在浏览器模式和session模式之间切换
page.get('https://www.example.com')  # 浏览器模式
page.change_mode('s')  # 切换到session模式
page.get('https://api.example.com/data')  # session模式

主要功能

元素查找

支持多种定位方式:

# CSS选择器
element = page.ele('.class-name')
element = page.ele('#element-id')

# XPath
element = page.ele('xpath://div[@class="example"]')

# 文本内容
element = page.ele('text:按钮文字')

# 属性
element = page.ele('@href=https://example.com')

元素操作

# 点击
element.click()

# 输入文本
element.input('文本内容')

# 获取属性
value = element.attr('href')

# 获取文本
text = element.text

# 截图
element.screenshot('element.png')

页面操作

# 页面截图
page.screenshot('page.png')

# 执行JavaScript
result = page.run_js('return document.title')

# 等待元素
page.wait.ele_loaded('#element-id')

# 处理弹窗
page.handle_alert(accept=True)

配置选项

浏览器配置

from dpclone import ChromiumOptions

# 创建配置对象
options = ChromiumOptions()

# 设置浏览器路径
options.set_browser_path('/path/to/chrome')

# 设置用户数据目录
options.set_user_data_path('/path/to/user/data')

# 添加启动参数
options.add_argument('--headless')

# 使用配置创建页面
page = ChromiumPage(options)

Session配置

from dpclone import SessionOptions

# 创建配置对象
options = SessionOptions()

# 设置请求头
options.set_headers({'User-Agent': 'Custom User Agent'})

# 设置代理
options.set_proxies({'http': 'http://proxy:port'})

# 使用配置创建会话
session = SessionPage(options)

许可证

本项目采用MIT许可证。详见LICENSE文件。

贡献

欢迎提交Issue和Pull Request来改进这个项目。

联系方式

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

dpclone-4.1.0.18.tar.gz (109.1 kB view details)

Uploaded Source

Built Distribution

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

dpclone-4.1.0.18-py3-none-any.whl (135.7 kB view details)

Uploaded Python 3

File details

Details for the file dpclone-4.1.0.18.tar.gz.

File metadata

  • Download URL: dpclone-4.1.0.18.tar.gz
  • Upload date:
  • Size: 109.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for dpclone-4.1.0.18.tar.gz
Algorithm Hash digest
SHA256 9847ef327317dcd40e2e8c3ce1c562150c4d909287aa535c465c1c0b1f49e506
MD5 82d62cb4cc5b62b5efa93fa70e97e05a
BLAKE2b-256 9a2696334d1b0f863dcd88d6625da852f66ad016a838c18c8d98b219206f7603

See more details on using hashes here.

File details

Details for the file dpclone-4.1.0.18-py3-none-any.whl.

File metadata

  • Download URL: dpclone-4.1.0.18-py3-none-any.whl
  • Upload date:
  • Size: 135.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for dpclone-4.1.0.18-py3-none-any.whl
Algorithm Hash digest
SHA256 b79541b8514ef7c4cb1b0465d5d9e3251f02ab38551f48c30c42b60e8338ad34
MD5 44e87cef43343a7b68bf8b5ecad942a7
BLAKE2b-256 43e6471b54abcc81bb385217b4be2ac4b48105c7635b0ca83b06b7f5ce6c2cae

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