Install
openclaw skills install @h8296699/real-estate-crawler综合房产中介网站爬虫技能,支持安居客、贝壳找房、链家、搜房网的数据抓取,包含反爬虫绕过策略和数据提取功能。
openclaw skills install @h8296699/real-estate-crawler这个技能整合了安居客和贝壳找房的爬虫经验,专门用于爬取中国主流房产中介网站的数据:
包含完整的反爬虫绕过策略和数据提取功能。
# 安装Python依赖
pip install requests beautifulsoup4 lxml pandas
# 安装agent-browser(已安装)
npm install -g agent-browser
agent-browser install
# Python模式
python3 scripts/anjuke_crawler.py
# agent-browser模式
bash scripts/bypass_anjuke.sh
# agent-browser模式(已验证有效)
bash scripts/bypass_ke.sh
# 需要验证码处理的链家爬虫
bash scripts/bypass_lianjia.sh
anjuke_crawler.pybypass_anjuke.shbypass_ke.shbypass_lianjia.shreal_estate_crawler.pyconfig/real_estate_config.pyCONFIG = {
"anjuke": {
"name": "安居客",
"url": "https://www.anjuke.com",
"anti_crawler_level": "高",
"anti_crawler_tips": "安居客有较强的反爬虫机制,需要模拟人类行为、使用随机延迟、设置cookie"
},
"ke": {
"name": "贝壳找房",
"url": "https://www.ke.com",
"anti_crawler_level": "较高",
"anti_crawler_tips": "贝壳找房对爬虫有较强的检测,建议使用代理IP、会话管理、模拟移动设备"
},
"lianjia": {
"name": "链家",
"url": "https://www.lianjia.com",
"anti_crawler_level": "高",
"anti_crawler_tips": "链家有很强的验证码机制,建议:1) 使用真实Cookie(先手动完成一次验证);2) 设置Referer和来源页;3) 使用代理IP;4) 限制访问频率"
},
"soufun": {
"name": "搜房网",
"url": "https://www.soufun.com",
"anti_crawler_level": "中",
"anti_crawler_tips": "搜房网反爬虫机制相对温和,但仍需注意频率控制"
}
}
# 设置移动设备UA
agent-browser set device "iPhone 14"
agent-browser set viewport 375 812
agent-browser set headers '{
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1"
}'
# 访问页面
agent-browser open "https://bj.ke.com/ershoufang"
agent-browser wait 5000
# 访问城市页面(无验证码)
agent-browser open "https://www.lianjia.com/city/"
agent-browser wait 4000
# 二手房页面可能需要验证码处理
agent-browser open "https://www.lianjia.com/ershoufang/bj/"
agent-browser wait 5000
# 如果出现验证码,需要人工干预
agent-browser pause
# 手动完成验证码
agent-browser continue
# 设置桌面浏览器UA
agent-browser set viewport 1920 1080
agent-browser set headers '{
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36"
}'
# 设置cookie模拟真实用户
agent-browser cookies set "ctid" "16"
agent-browser cookies set "twe" "2"
agent-browser cookies set "obtain_by" "3"
房产数据包含以下字段:
{
"title": "房源标题",
"price": "总价(万元)",
"avg_price": "均价(元/㎡)",
"area": "面积(㎡)",
"location": "位置",
"house_type": "户型",
"age": "建筑年代",
"orientation": "朝向",
"decoration": "装修状态",
"source": "来源网站",
"url": "房源URL",
"timestamp": "爬取时间"
}
# 使用agent-browser
bash scripts/bypass_ke.sh
# 或者使用Python脚本
python3 scripts/real_estate_crawler.py -w ke -c "北京" -p 1 -o ke_properties.json
bash scripts/bypass_anjuke.sh
python3 scripts/batch_crawler.py \
--websites "anjuke,ke" \
--cities "北京,上海,广州,深圳" \
--pages 3 \
--format "csv"
real-estate-crawler/
├── SKILL.md # 技能文档
├── README.md # 使用指南
├── main.py # 主程序入口
├── scripts/
│ ├── anjuke_crawler.py # 安居客爬虫
│ ├── bypass_anjuke.sh # 安居客反爬虫脚本
│ ├── bypass_ke.sh # 贝壳找房脚本(已验证)
│ ├── bypass_lianjia.sh # 链家脚本(需要验证码处理)
│ ├── bypass_soufun.sh # 搜房网脚本
│ ├── real_estate_crawler.py # 通用爬虫
│ └── batch_crawler.py # 批量爬取脚本
├── config/
│ ├── real_estate_config.py # 网站配置
│ ├── user_agents.txt # User-Agent列表
│ └── proxy_list.txt # 代理IP列表
├── docs/
│ ├── captcha_strategies.md # 验证码绕过策略
│ ├── anti_crawler_guide.md # 反爬虫指南
│ └── data_extraction.md # 数据提取指南
└── output/
├── data/
├── screenshots/
└── logs/
如有问题或建议,请联系技能开发者。
警告: 使用本技能爬取数据时,请遵守相关法律和网站条款。