A common spider tool based on Selenium
Project description
AutoScraperX
AutoScraperX 是一个基于 Selenium 和 undetected_chromedriver 的通用爬虫框架,旨在提供强大而灵活的 Web 自动化功能。它支持自动化浏览、元素操作、页面截图、cookie 管理等功能,适用于各种爬取任务。
功能特点
- 支持多种浏览器选项(无头模式、用户数据目录、自定义 Chrome 位置等)
- 支持移动端仿真(iPhone X 模拟)
- 智能等待机制,确保元素加载完毕再进行操作
- 页面截图,可保存完整网页截图
- Cookie 读写,支持持久化登录
- 自动滚动、刷新、切换标签页等操作
- 异常处理,确保爬虫稳定运行
安装
确保你的环境中安装了以下依赖:
pip install selenium undetected-chromedriver beautifulsoup4
此外,请下载并配置相应的 WebDriver,例如 ChromeDriver。
使用方法
初始化爬虫
from AutoScraperX import common_spider # 确保 Spider 类已正确导入
options = {
'headless': True, # 以无头模式运行
'binary_location': "C:\\Path\\To\\chrome.exe", # 指定 Chrome 位置
'user_data_dir': "C:\\Users\\User\\AppData\\Local\\Google\\Chrome\\User Data",
'driver_executable_path': "C:\\Path\\To\\chromedriver.exe"
}
spider = common_spider.Spider(options)
打开网页
spider.open("https://example.com")
获取页面源码
html = spider.get_source()
print(html)
等待元素加载
spider.wait_element("//div[@id='content']", by=By.XPATH)
进行交互
spider.comment("测试评论", "#comment-box")
保存截图
spider.save_screenshot("screenshot.png")
处理 Cookie
spider.save_cookie("cookies.pkl")
spider.load_cookie("cookies.pkl", domain="example.com")
退出爬虫
spider.quit()
贡献
如果你对 AutoScraperX 有任何改进建议或贡献,请提交 PR 或 Issue。
联系方式
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
autoscraperx-0.1.2.tar.gz
(6.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file autoscraperx-0.1.2.tar.gz.
File metadata
- Download URL: autoscraperx-0.1.2.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
538be83acb8cff97386baf5fd25d1d3c86db9f3234f7605dc226f5b2883dbe21
|
|
| MD5 |
0cf31a94d61d99f3360447f3eaf59c27
|
|
| BLAKE2b-256 |
b07e308a5683b06cf89c9eda3274665dfb52e99ab4dcab55c7bb414cd46fdfb8
|
File details
Details for the file AutoScraperX-0.1.2-py3-none-any.whl.
File metadata
- Download URL: AutoScraperX-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b51b485b7585f9a281c8b58e5314556925fc1defe52921360f601edba69c11f0
|
|
| MD5 |
1702b9d67998100157a828ca50532c99
|
|
| BLAKE2b-256 |
57e32081ae500f2d2b8f11e7bb7735687799b2912ba072607e3e212b0c7fa5b4
|