# house-renting-spider (English version)
A web spider for crawling accommodation rental information in [Douban Group](https://www.douban.com/group/), which is a well-known Chinese online community.
## System Requirements:
- Python 2.7
- pip
- (Optional) [virtualenv](https://virtualenv.pypa.io/en/latest/)
## To start
```bash
# Clone the repo
$ git clone https://github.com/PeggyZWY/house-renting-spider
$ cd house-renting-spider
# Install requirements
$ pip install -r requirements.txt
# Modify config.ini
$ vim config.ini
```
Configure in **config.ini**:
1. `key_search_word_list` is the wanted keywords for the rented accommodation. If there is more than one keyword, use `,` to delimit them.
2. `custom_black_list` is the unwanted keyword. Similarly, if there is more than one keyword, use `,` to delimit them.
3. `start_time` is the earliest date for the post posted. Set the date in the format like `2018-12-31`.
4. Under the option of `[douban]`, `douban_cookie` and `douban_sleep_time` don't need to be changed, since the programme will set the cookie automatically. It is recommended to set `douban_sleep_time` to 1 second, in order not to be defined as a web spider by Douban.com.
For example:
![config](img/config.png)
After finishing configuration, type the following in the terminal:
```bash
$ python houseRentingSpider.py
```
Then wait for the spider to work...
When it finishes, information like the following will be shown:
![config](img/finish_hint.png)
According to the address, open the HTML in any brower and the example results are shown as followes:
![config](img/result.png)
## Others
In `houseRentingSpider.py`, there are groups set as following for example.
![config](img/setGroup.png)
The group number in the URL list in `douban_url` should be correspondent to the names in `douban_url_name`.
In all, after setting the groups here, and setting keywords in `config.ini`, you can have your own web spider.
----------------------
# house-renting-spider (Chinese version)
豆瓣小组上海租房爬虫
## System Requirements:
- Python 2.7
- pip
- (Optional) [virtualenv](https://virtualenv.pypa.io/en/latest/)
## To start
```bash
# Clone the repo
$ git clone https://github.com/PeggyZWY/house-renting-spider
$ cd house-renting-spider
# Install requirements
$ pip install -r requirements.txt
# Modify config.ini
$ vim config.ini
```
在**config.ini**里配置并保存:
1. `key_search_word_list`为想要搜索的关键词。如果有多个关键词,请用**英文**逗号`,`隔开
2. `custom_black_list`为拒绝的关键词黑名单。同样如果有多个关键词,请用**英文**逗号`,`隔开
3. `start_time`为要搜索在这个时间之后的信息。请用`2018-12-31`这种格式表示日期
4. `[douban]`这个option下的`douban_cookie`和`douban_sleep_time`不需要改变。程序里会自动设置cookie;`douban_sleep_time`设为1秒钟比较合适,防止豆瓣反爬虫封号
比如:
![config](img/config.png)
配置好之后继续在终端输入:
```bash
$ python houseRentingSpider.py
```
然后就等爬虫爬呀爬。
结束之后,命令行有提示。比如:
![config](img/finish_hint.png)
根据提示打开此HTML文件后会出现结果。比如(截图仅截取部分结果):
![config](img/result.png)
配色是根据豆瓣来的嘿嘿:)
## Others
在`houseRentingSpider.py`里,现在设置了如下小组。
![config](img/setGroup.png)
`douban_url`这个数组里URL的参数中group的值以及`douban_url_name`数组里的小组名要一一对应。
也就是说,只要你是在**豆瓣小组**里对**关键字**进行爬取,在这里设置小组,在`config.ini`设置关键词,就可以定制出自己的爬虫。
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
爬虫(Web Crawler)是一种自动化程序,用于从互联网上收集信息。其主要功能是访问网页、提取数据并存储,以便后续分析或展示。爬虫通常由搜索引擎、数据挖掘工具、监测系统等应用于网络数据抓取的场景。 爬虫的工作流程包括以下几个关键步骤: URL收集: 爬虫从一个或多个初始URL开始,递归或迭代地发现新的URL,构建一个URL队列。这些URL可以通过链接分析、站点地图、搜索引擎等方式获取。 请求网页: 爬虫使用HTTP或其他协议向目标URL发起请求,获取网页的HTML内容。这通常通过HTTP请求库实现,如Python中的Requests库。 解析内容: 爬虫对获取的HTML进行解析,提取有用的信息。常用的解析工具有正则表达式、XPath、Beautiful Soup等。这些工具帮助爬虫定位和提取目标数据,如文本、图片、链接等。 数据存储: 爬虫将提取的数据存储到数据库、文件或其他存储介质中,以备后续分析或展示。常用的存储形式包括关系型数据库、NoSQL数据库、JSON文件等。 遵守规则: 为避免对网站造成过大负担或触发反爬虫机制,爬虫需要遵守网站的robots.txt协议,限制访问频率和深度,并模拟人类访问行为,如设置User-Agent。 反爬虫应对: 由于爬虫的存在,一些网站采取了反爬虫措施,如验证码、IP封锁等。爬虫工程师需要设计相应的策略来应对这些挑战。 爬虫在各个领域都有广泛的应用,包括搜索引擎索引、数据挖掘、价格监测、新闻聚合等。然而,使用爬虫需要遵守法律和伦理规范,尊重网站的使用政策,并确保对被访问网站的服务器负责。
资源推荐
资源详情
资源评论
收起资源包目录
A crawler for accommodation rental information in Douban Group 豆瓣小组上海租房爬虫.zip (12个子文件)
SJT-code
lib
resultPage.css 603B
resultPage.js 625B
houseRentingSpider.py 12KB
config.ini 157B
img
setGroup.png 186KB
result.png 623KB
finish_hint.png 28KB
config.png 46KB
requirements.txt 39B
.gitignore 15B
Config.py 1KB
README.md 4KB
共 12 条
- 1
资源评论
JJJ69
- 粉丝: 6214
- 资源: 5783
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功