|
| 1 | +Metadata-Version: 2.1 |
| 2 | +Name: AutoScraperX |
| 3 | +Version: 0.1.0 |
| 4 | +Summary: A common spider tool based on Selenium |
| 5 | +Home-page: https://github.com/chenziying1/AutoScraperX |
| 6 | +Author: czy |
| 7 | +Author-email: 1060324818@qq.com |
| 8 | +Classifier: Programming Language :: Python :: 3 |
| 9 | +Classifier: Operating System :: OS Independent |
| 10 | +Requires-Python: >=3.6 |
| 11 | +Description-Content-Type: text/markdown |
| 12 | +Requires-Dist: selenium |
| 13 | +Requires-Dist: beautifulsoup4 |
| 14 | +Requires-Dist: undetected-chromedriver |
| 15 | + |
| 16 | +# AutoScraperX |
| 17 | + |
| 18 | +AutoScraperX 是一个基于 Selenium 和 undetected_chromedriver 的通用爬虫框架,旨在提供强大而灵活的 Web 自动化功能。它支持自动化浏览、元素操作、页面截图、cookie 管理等功能,适用于各种爬取任务。 |
| 19 | + |
| 20 | +## 功能特点 |
| 21 | + |
| 22 | +* **支持多种浏览器选项**(无头模式、用户数据目录、自定义 Chrome 位置等) |
| 23 | +* **支持移动端仿真**(iPhone X 模拟) |
| 24 | +* **智能等待机制**,确保元素加载完毕再进行操作 |
| 25 | +* **页面截图**,可保存完整网页截图 |
| 26 | +* **Cookie 读写**,支持持久化登录 |
| 27 | +* **自动滚动、刷新、切换标签页等操作** |
| 28 | +* **异常处理**,确保爬虫稳定运行 |
| 29 | + |
| 30 | +## 安装 |
| 31 | + |
| 32 | +确保你的环境中安装了以下依赖: |
| 33 | + |
| 34 | +``` |
| 35 | +pip install selenium undetected-chromedriver beautifulsoup4 |
| 36 | +``` |
| 37 | + |
| 38 | +此外,请下载并配置相应的 WebDriver,例如 [ChromeDriver]()。 |
| 39 | + |
| 40 | +## 使用方法 |
| 41 | + |
| 42 | +### 初始化爬虫 |
| 43 | + |
| 44 | +``` |
| 45 | +from common_spider import Spider |
| 46 | + |
| 47 | +options = { |
| 48 | + 'headless': True, # 以无头模式运行 |
| 49 | + 'binary_location': "C:\\Path\\To\\chrome.exe", # 指定 Chrome 位置 |
| 50 | + 'user_data_dir': "C:\\Users\\User\\AppData\\Local\\Google\\Chrome\\User Data", |
| 51 | + 'driver_executable_path': "C:\\Path\\To\\chromedriver.exe" |
| 52 | +} |
| 53 | + |
| 54 | +spider = Spider(options) |
| 55 | +``` |
| 56 | + |
| 57 | +### 打开网页 |
| 58 | + |
| 59 | +``` |
| 60 | +spider.open("https://example.com") |
| 61 | +``` |
| 62 | + |
| 63 | +### 获取页面源码 |
| 64 | + |
| 65 | +``` |
| 66 | +html = spider.get_source() |
| 67 | +print(html) |
| 68 | +``` |
| 69 | + |
| 70 | +### 等待元素加载 |
| 71 | + |
| 72 | +``` |
| 73 | +spider.wait_element("//div[@id='content']", by=By.XPATH) |
| 74 | +``` |
| 75 | + |
| 76 | +### 进行交互 |
| 77 | + |
| 78 | +``` |
| 79 | +spider.comment("测试评论", "#comment-box") |
| 80 | +``` |
| 81 | + |
| 82 | +### 保存截图 |
| 83 | + |
| 84 | +``` |
| 85 | +spider.save_screenshot("screenshot.png") |
| 86 | +``` |
| 87 | + |
| 88 | +### 处理 Cookie |
| 89 | + |
| 90 | +``` |
| 91 | +spider.save_cookie("cookies.pkl") |
| 92 | +spider.load_cookie("cookies.pkl", domain="example.com") |
| 93 | +``` |
| 94 | + |
| 95 | +### 退出爬虫 |
| 96 | + |
| 97 | +``` |
| 98 | +spider.quit() |
| 99 | +``` |
| 100 | + |
| 101 | +## 贡献 |
| 102 | + |
| 103 | +如果你对 AutoScraperX 有任何改进建议或贡献,请提交 PR 或 Issue。 |
| 104 | + |
| 105 | +## 联系方式 |
| 106 | + |
| 107 | +* 作者: czy |
| 108 | +* 邮箱: [1060324818@qq.com]() |
| 109 | +* 项目地址:https://github.com/chenziying1/AutoScraperX |
| 110 | +* 项目示例:https://github.com/chenziying1/AutoScraperX/test/test.py |
0 commit comments