Python 之scrapy框架58同城招聘爬取案例
一、项目目录结构:

代码如下:
# -*- coding: utf-8 -*- # Define here the models for your scraped items
#
# See documentation in:
# https://doc.scrapy.org/en/latest/topics/items.html import scrapy class Job58CityItem(scrapy.Item):
# define the fields for your item here like:
# name = scrapy.Field()
job_name = scrapy.Field()
money = scrapy.Field()
job_wel = scrapy.Field()
company = scrapy.Field()
position_type = scrapy.Field()
xueli = scrapy.Field()
jingyan = scrapy.Field()
address = scrapy.Field()
# -*- coding: utf-8 -*-
import scrapy
from ..items import Job58CityItem class JobsSpider(scrapy.Spider):
name = 'jobs'
allowed_domains = ['58.com']
# 配置起始页url
offset = 1
url = "https://cd.58.com/job/pn{0}/"
start_urls = [url.format(str(offset))] #解析html内容
def parse(self, response):
for each in response.xpath("//ul[@id='list_con']/li"):
item = Job58CityItem()
item['job_name'] = each.xpath(".//span[@class='name']/text()").extract()[0]
money_list = each.xpath(".//p[@class='job_salary']/text()").extract()
money = "未知"
if len(money_list) > 0:
money = money_list[0]
item['money'] = money
span = each.xpath(".//div[@class='job_wel clearfix']/span")
item['job_wel'] = []
for i in span:
item['job_wel'].append(i.xpath("./text()").extract()[0])
item['company'] = each.xpath(".//div[@class='comp_name']/a/text()").extract()[0]
item['position_type'] = each.xpath(".//span[@class='cate']/text()").extract()[0]
item['xueli'] = each.xpath(".//span[@class='xueli']/text()").extract()[0]
item['jingyan'] = each.xpath(".//span[@class='jingyan']/text()").extract()[0]
item['address'] = each.xpath("//span[@class='address']/text()").extract()[0]
yield item
if self.offset < 100:
self.offset += 1
yield scrapy.Request("https://cd.58.com/job/pn{0}/".format(str(self.offset)), callback=self.parse)
from scrapy import cmdline if __name__ == '__main__':
cmdline.execute("scrapy crawl jobs".split())
数据:

源码链接:https://github.com/yangsphp/Scrapy-master
Python 之scrapy框架58同城招聘爬取案例的更多相关文章
- python爬虫 scrapy框架(一)爬取壁纸照片
此项目仅供学习参考, 不用于任何商业用途 若侵权留言,立刻删除 刚入门爬虫不久,一心想找个网站试试,然后朋友推荐了这个壁纸网站
- Scrapy 框架 CrawlSpider 全站数据爬取
CrawlSpider 全站数据爬取 创建 crawlSpider 爬虫文件 scrapy genspider -t crawl chouti www.xxx.com import scrapy fr ...
- scrapy框架用CrawlSpider类爬取电影天堂.
本文使用CrawlSpider方法爬取电影天堂网站内国内电影分类下的所有电影的名称和下载地址 CrawlSpider其实就是Spider的一个子类. CrawlSpider功能更加强大(链接提取器,规 ...
- 爬虫(十七):Scrapy框架(四) 对接selenium爬取京东商品数据
1. Scrapy对接Selenium Scrapy抓取页面的方式和requests库类似,都是直接模拟HTTP请求,而Scrapy也不能抓取JavaScript动态谊染的页面.在前面的博客中抓取Ja ...
- python爬虫scrapy框架
Scrapy 框架 关注公众号"轻松学编程"了解更多. 一.简介 Scrapy是用纯Python实现一个为了爬取网站数据.提取结构性数据而编写的应用框架,用途非常广泛. 框架的力量 ...
- python爬虫scrapy框架——人工识别登录知乎倒立文字验证码和数字英文验证码(2)
操作环境:python3 在上一文中python爬虫scrapy框架--人工识别知乎登录知乎倒立文字验证码和数字英文验证码(1)我们已经介绍了用Requests库来登录知乎,本文如果看不懂可以先看之前 ...
- Python爬虫(四)——开封市58同城数据模型训练与检测
前文参考: Python爬虫(一)——开封市58同城租房信息 Python爬虫(二)——对开封市58同城出租房数据进行分析 Python爬虫(三)——对豆瓣图书各模块评论数与评分图形化分析 数据的构建 ...
- [Python爬虫] 使用 Beautiful Soup 4 快速爬取所需的网页信息
[Python爬虫] 使用 Beautiful Soup 4 快速爬取所需的网页信息 2018-07-21 23:53:02 larger5 阅读数 4123更多 分类专栏: 网络爬虫 版权声明: ...
- 【图文详解】scrapy爬虫与动态页面——爬取拉勾网职位信息(2)
上次挖了一个坑,今天终于填上了,还记得之前我们做的拉勾爬虫吗?那时我们实现了一页的爬取,今天让我们再接再厉,实现多页爬取,顺便实现职位和公司的关键词搜索功能. 之前的内容就不再介绍了,不熟悉的请一定要 ...
随机推荐
- 跳過 Windows RT的UI
RT启动进入常规桌面 微软Surface RT发布的时间已经不短了,相信很多朋友都已经熟悉了这个全新的平板,并且已经上手.Surface RT开机默认进入的界面为Windows UI,这对于经常使用A ...
- 【oracle11g,18】存储结构:暂时表,手工条带化,表/索引迁移表空间,删除表,外部表
一. 暂时表 暂时表放在暂时表空间,不生成redo,仅仅有undo. 在暂时表中能够创建索引.视图及触发器,还能够使用"Export and Import(导出和导入)"或&quo ...
- 打造atom成为golang开发神器
在我在Windows系统上开发的日子里.我使用IDE开发数年之久.比如Visual Basic IDE, Borland Delphi IDE, Visual C++ 和最后的Visual Studi ...
- LeetCode 645. Set Mismatch (集合不匹配)
The set S originally contains numbers from 1 to n. But unfortunately, due to the data error, one of ...
- LeetCode 69. Sqrt(x) (平方根)
Implement int sqrt(int x). Compute and return the square root of x. x is guaranteed to be a non-nega ...
- ios11--UIButton
// // ViewController.m // 02-UIButton(在代码中使用) // #import "ViewController.h" @interface Vie ...
- Android横竖屏切换不重新调用onCreate()
再次感叹Android的碎片化!!!! 设置AndroidManifest.xml中Activity的android:configChanges=”keyboardHidden|orientation ...
- Linux gadget驱动分析2------设备识别过程
设备连上主机之后,设备驱动做了的事. 设备连上host的port之后,主机端会有一套策略发送请求获取device的一系列描述符.进行枚举过程.找到适合该device的驱动. 这样就可以与device进 ...
- codeforce 1073E. Segment Sum
看到这个就是数位DP了,然而细节极多,对于i=1状态直接判了,还有最后一位直接算了 设f[i][zt][0/1]表示枚举到第i位,用了那些数字,是否有前导0(前导0不计入数字,否则就不知道后面有没有0 ...
- 实现https
实现https 环境 1.三台主机分别为A,B,C. 2.A主机设置为CA和DNS服务器,ip为192.168.213.129 3.B主机为client,ip为192.168.213.253 4.C主 ...