Công cụ crawl dữ liệu từ Zhihu với giao diện CLI thân thiện, hỗ trợ crawl nhiều loại nội dung khác nhau.
- 🔗 Crawl từ link cụ thể: Hỗ trợ crawl trực tiếp từ URL Zhihu
- 🔍 Tìm kiếm theo từ khóa: Tìm kiếm và crawl nội dung theo từ khóa
- 👤 Crawl thông tin người dùng: Lấy thông tin profile và hoạt động của user
- 🔥 Crawl hot list: Lấy dữ liệu từ bảng xếp hạng hot
- 📚 Hỗ trợ nhiều loại nội dung:
- Truyện/Tiểu thuyết
- Bài viết
- Câu hỏi & Câu trả lời
- Video
- 💾 Xuất dữ liệu: Tự động lưu kết quả ra file JSON/TXT
- ⚙️ Cấu hình linh hoạt: Hỗ trợ proxy, cookie tùy chỉnh
- Python 3.13+
- Node.js (cho JavaScript execution)
- Git
# Clone repository
git clone https://github.com/thucpru/zhihu-crawl.git
cd zhihu-crawl
# Tạo virtual environment
python -m venv venv
# Kích hoạt virtual environment
# Windows:
.\venv\Scripts\activate
# Linux/Mac:
source venv/bin/activate
# Cài đặt dependencies
pip install -r requirements.txtpython zhihu_crawler_cli.py============================================================
🐍 ZHIHU CRAWLER CLI - CÔNG CỤ CRAWL ZHIHU
============================================================
📚 Hỗ trợ crawl: Truyện, Bài viết, Câu hỏi, Video
🔍 Tìm kiếm theo từ khóa, crawl từ link cụ thể
💾 Tự động lưu dữ liệu ra file JSON/TXT
============================================================
📋 MENU CHÍNH:
1. 🔗 Crawl từ link cụ thể
2. 🔍 Tìm kiếm và crawl theo từ khóa
3. 👤 Crawl thông tin người dùng
4. 🔥 Crawl hot list (bảng xếp hạng)
5. ⚙️ Cài đặt proxy/cookie
6. 📊 Xem thống kê crawl
0. 🚪 Thoát
# Nhập URL Zhihu bất kỳ
https://www.zhihu.com/question/123456789# Nhập từ khóa muốn tìm
python programming# Nhập username hoặc user ID
excited-vczh- gevent: Async networking
- requests: HTTP requests
- loguru: Logging
- beautifulsoup4: HTML parsing
- lxml: XML/HTML processing
- requests-html: JavaScript rendering
- PyExecJS: JavaScript execution
- my_fake_useragent: User agent rotation
# Cấu hình proxy trong menu settings
proxy = {
'http': 'http://proxy:port',
'https': 'https://proxy:port'
}# Thêm cookie d_c0 để tăng tỷ lệ thành công
d_c0 = "your_cookie_value"zhihu-crawl/
├── zhihu_crawler/ # Core crawler modules
│ ├── __init__.py
│ ├── zhihu_scraper.py # Main scraper class
│ ├── page_iterators.py # Page iteration logic
│ ├── extractors.py # Data extraction
│ ├── constants.py # Constants
│ ├── exceptions.py # Custom exceptions
│ └── zhihu_types.py # Type definitions
├── utils/ # Utility functions
│ ├── __init__.py
│ └── zhihu_utils.py # Helper functions
├── common/ # Common modules
│ ├── __init__.py
│ ├── encrypt.py # Encryption utilities
│ └── encrypt.js # JavaScript encryption
├── docs/ # Documentation
├── run/ # Runtime data
├── zhihu_crawler_cli.py # CLI interface
├── requirements.txt # Dependencies
├── .gitignore # Git ignore rules
└── README.md # This file
```python
# Sử dụng monkey patch cho async operations
from gevent import monkey
monkey.patch_all()
from zhihu_crawler import ZhiHuScraper
if __name__ == '__main__':
# Khởi tạo scraper
scraper = ZhiHuScraper()
# Cài đặt proxy (tùy chọn)
scraper.set_proxy({
'http': 'http://127.0.0.1:8125',
'https': 'http://127.0.0.1:8125'
})
# Cài đặt cookie (khuyến nghị)
scraper.set_cookie({
'd_c0': 'your_d_c0_cookie_value'
})
# Tìm kiếm và crawl
for result in scraper.search_crawl(keyword='python programming', nums=10):
print(result)
# Crawl thông tin user
for user_info in scraper.user_crawler(
user_id='excited-vczh',
answer_nums=20,
comment_nums=10
):
print(user_info)
# Crawl hot questions
for hot_question in scraper.hot_questions_crawl(
question_nums=10,
drill_down_nums=5
):
print(hot_question)
- Fork repository
- Tạo feature branch (
git checkout -b feature/AmazingFeature) - Commit changes (
git commit -m 'Add some AmazingFeature') - Push to branch (
git push origin feature/AmazingFeature) - Tạo Pull Request
Dự án này được phân phối dưới giấy phép MIT. Xem file LICENSE để biết thêm chi tiết.
- Chỉ sử dụng cho mục đích học tập và nghiên cứu
- Tuân thủ Terms of Service của Zhihu
- Không spam hoặc crawl quá nhiều requests trong thời gian ngắn
- Khuyến nghị sử dụng delay giữa các requests
- Tự chịu trách nhiệm về việc sử dụng công cụ này
-
ModuleNotFoundError: No module named 'execjs'
pip install PyExecJS
-
ModuleNotFoundError: No module named 'my_fake_useragent'
pip install my_fake_useragent
-
Lỗi build lxml trên Windows
pip install lxml>=4.9.3 -
JavaScript execution error
- Đảm bảo Node.js đã được cài đặt
- Kiểm tra file
common/encrypt.jstồn tại
- GitHub: @thucpru
- Email: thucpru@gmail.com
- Repository: zhihu-crawl
⭐ Nếu dự án hữu ích, hãy cho một star nhé! ⭐
- v1.0.0: Initial release với CLI interface
- Thêm hỗ trợ Python 3.13+
- Cập nhật dependencies và fix các lỗi environment
- Thêm .gitignore và documentation đầy đủ