littlebot
Published on 2025-04-15 / 1 Visits
0

【源码】基于Python的新闻和职位爬虫系统

项目简介

本项目是基于Python和Scrapy框架开发的新闻和职位爬虫系统。它能抓取百度百家号的新闻内容以及前程无忧的职位信息,利用Redis进行任务调度和数据存储。项目既支持本地开发和部署,也能通过Scrapyd实现远程爬虫任务的调度与管理。

项目的主要特性和功能

  • 新闻爬虫:可抓取百度百家号的新闻内容。
  • 职位爬虫:能抓取前程无忧的职位信息。
  • Redis任务调度:借助Redis完成爬虫任务的调度和数据存储。
  • Scrapyd部署:支持通过Scrapyd远程调度和管理爬虫任务。
  • 浏览器驱动支持:支持Firefox和Chrome浏览器驱动,保障爬虫在无头模式下运行。

安装使用步骤

1. 环境准备

确保已安装以下依赖: - Python 3 - Redis - Firefox或Chrome浏览器及其对应的驱动(geckodriver或chromedriver)

2. 安装依赖

```shell brew install redis brew services run redis

vim /usr/local/etc/redis.conf requirepass 123456

pip install scrapy scrapy-redis scrapy-selenium

brew cask install geckodriver brew cask install chromedriver ```

3. 复制项目并创建虚拟环境

shell cd NEWSCrawler python3 -m venv venv source venv/bin/activate pip install -r requirements.txt

4. 修改配置文件

修改NEWSCrawler/NEWSCrawler/settings.py文件中的Redis配置: python REDIS_URL = 'redis://:密码@主机名:端口'

5. 启动爬虫

```shell scrapy crawl author_baidu

scrapy crawl w1job_search ```

6. 部署到Scrapyd

```shell pip install scrapyd scrapyd-client

scrapyd

scrapyd-deploy

curl http://localhost:6800/schedule.json -d project=NEWSCrawler -d spider=w1job_search curl http://localhost:6800/schedule.json -d project=NEWSCrawler -d spider=author_baidu ```

7. 管理爬虫任务

```shell curl http://localhost:6800/cancel.json -d project=NEWSCrawler -d job={job}

curl http://localhost:6800/delproject.json -d project=NEWSCrawler

curl http://127.0.0.1:6800/daemonstatus.json

curl http://127.0.0.1:6800/listprojects.json

curl http://127.0.0.1:6800/listspiders.json?project=NEWSCrawler

curl http://127.0.0.1:6800/listversions.json?project=NEWSCrawler

curl http://127.0.0.1:6800/listjobs.json?project=NEWSCrawler ```

通过以上步骤,可轻松搭建、运行和管理本项目的爬虫任务。

下载地址

点击下载 【提取码: 4003】【解压密码: www.makuang.net】