Python网络爬虫案例(二)——爬取招聘信息网站
利用Python,爬取 51job 上面有关于 IT行业 的招聘信息
版权声明:未经博主授权,内容严禁分享转载


案例代码:
# __author : "J"
# date : 2018-03-07 import urllib.request
import re
import pymysql connection = pymysql.connect(host='127.0.0.1', port=3306, user='root', password='******', db='51job',
charset='utf8')
cursor = connection.cursor() num = 0
textnum = 1
while num < 18: num += 1
# 51job IT行业招聘网址 需要翻页,大约800多条数据
request = urllib.request.Request(
"http://search.51job.com/list/120000,000000,0100,32,9,99,%2B,2," + str(
num) + ".html?lang=c&stype=1&postchannel=0000&workyear=99&cotype=99°reefrom=99&jobterm=99&companysize=99&lonlat=0%2C0&radius=-1&ord_field=0&confirmdate=9&fromType=1&dibiaoid=0&address=&line=&specialarea=00&from=&welfare=") response = urllib.request.urlopen(request)
my_html = response.read().decode('gbk')
# print(my_html) my_re = re.compile(r'href="(.*?)" onmousedown="">')
second_html_list = re.findall(my_re, my_html) for i in second_html_list:
second_request = urllib.request.Request(i)
second_response = urllib.request.urlopen(second_request)
second_my_html = second_response.read().decode('gbk')
# 职位 地区 工资 公司名称 公司简介
# 工作经验 学历 招聘人数 发布时间
# 职位信息 联系方式 公司信息
second_my_re = re.compile('<h1 title=.*?">(.*?)<input value=.*?' +
'<span class="lname">(.*?)</span>.*?' +
'<strong>(.*?)</strong>.*?' +
'target="_blank" title=".*?">(.*?)<em class="icon_b i_link"></em></a>.*?' +
'<p class="msg ltype">(.*?)</p>.*?</div>'
, re.S | re.M | re.I)
second_html_news = re.findall(second_my_re, second_my_html)[0]
zhiwei = second_html_news[0].replace("\n|\t|\r|\r\n", '').replace(" ", '').replace(" ", '').replace(
" ",
'')
diqu = second_html_news[1].replace("\n|\t|\r|\r\n", '').replace(" ", '').replace(" ", '').replace(
" ",
'')
gongzi = second_html_news[2].replace("\n|\t|\r|\r\n", '').replace(" ", '').replace(" ", '').replace(
" ",
'')
gongsimingcheng = second_html_news[3].replace("\n|\t|\r|\r\n", '').replace(" ", '').replace(" ",
'').replace(
" ",
'')
gongsijianjie = second_html_news[4].replace("\n|\t|\r|\r\n", '').replace(" ", '').replace(" ",
'').replace(
" ",
'')
# print(zhiwei,diqu,gongzi,gongsimingcheng,gongsijianjie)
try:
second_my_re = re.compile('<span class="sp4"><em class="i1"></em>(.*?)</span>'
, re.S | re.M | re.I)
yaoqiu = re.findall(second_my_re, second_my_html)[0]
except Exception as e:
pass
try:
second_my_re = re.compile('<span class="sp4"><em class="i2"></em>(.*?)</span>'
, re.S | re.M | re.I)
yaoqiu += ' | ' + re.findall(second_my_re, second_my_html)[0]
except Exception as e:
pass
try:
second_my_re = re.compile('<span class="sp4"><em class="i3"></em>(.*?)</span>'
, re.S | re.M | re.I)
yaoqiu += ' | ' + re.findall(second_my_re, second_my_html)[0]
except Exception as e:
pass
try:
second_my_re = re.compile('<span class="sp4"><em class="i4"></em>(.*?)</span>'
, re.S | re.M | re.I)
yaoqiu += ' | ' + re.findall(second_my_re, second_my_html)[0]
except Exception as e:
pass
# print(yaoqiu)
second_my_re = re.compile('<div class="bmsg job_msg inbox">(.*?)<div class="mt10">'
, re.S | re.M | re.I)
gangweizhize = re.findall(second_my_re, second_my_html)[0].replace("\r\n|\n|\t|\r", '').replace(" ",
'').replace(
" ", '').replace(" ", '') dr = re.compile(r'<[^>]+>', re.S)
gangweizhize = dr.sub('', gangweizhize) second_my_re = re.compile('<span class="bname">联系方式</span>(.*?)<div class="tBorderTop_box">'
, re.S | re.M | re.I)
lianxifangshi = re.findall(second_my_re, second_my_html)[0].replace("\r\n|\n|\t|\r", '').replace(" ", '') dr = re.compile(r'<[^>]+>', re.S)
lianxifangshi = dr.sub('', lianxifangshi)
lianxifangshi = re.sub('\s', '', lianxifangshi) second_my_re = re.compile('<span class="bname">公司信息</span>(.*?)<div class="tCompany_sidebar">'
, re.S | re.M | re.I)
gongsixinxi = re.findall(second_my_re, second_my_html)[0].replace(" ", '')
dr = re.compile(r'<[^>]+>', re.S)
gongsixinxi = dr.sub('', gongsixinxi)
gongsixinxi = re.sub('\s', '', gongsixinxi) print('第 '+str(textnum) + ' 条数据 **********************************************')
print(zhiwei, diqu, gongzi, gongsimingcheng, gongsijianjie, yaoqiu, gangweizhize, lianxifangshi, gongsixinxi)
textnum += 1
# try:
# sql = "INSERT INTO `jobNews` (`position`,`region`,`Pay`,`company`,`Nature`,`Requirement`,`Job_information`,`Contact_information`,`Company_information`) VALUES ('" + zhiwei + "','" + diqu + "','" + gongzi + "','" + gongsimingcheng + "','" + gongsijianjie + "','" + yaoqiu + "','" + gangweizhize + "','" + lianxifangshi + "','" + gongsixinxi + "')"
# cursor.execute(sql)
# connection.commit()
# print('存储成功!')
# except Exception as e:
# pass cursor.close()
connection.close()
效果:

我正则表达式用的不好,所以写的很麻烦,接受建议~
Python网络爬虫案例(二)——爬取招聘信息网站的更多相关文章
- Python 网络爬虫 002 (入门) 爬取一个网站之前,要了解的知识
网站站点的背景调研 1. 检查 robots.txt 网站都会定义robots.txt 文件,这个文件就是给 网络爬虫 来了解爬取该网站时存在哪些限制.当然了,这个限制仅仅只是一个建议,你可以遵守,也 ...
- Python网络爬虫与如何爬取段子的项目实例
一.网络爬虫 Python爬虫开发工程师,从网站某一个页面(通常是首页)开始,读取网页的内容,找到在网页中的其它链接地址,然后通过这些链接地址寻找下一个网页,这样一直循环下去,直到把这个网站所有的网页 ...
- 【Python网络爬虫三】 爬取网页新闻
学弟又一个自然语言处理的项目,需要在网上爬一些文章,然后进行分词,刚好牛客这周的是从一个html中找到正文,就实践了一下.写了一个爬门户网站新闻的程序 需求: 从门户网站爬取新闻,将新闻标题,作者,时 ...
- Python 网络爬虫实战:爬取 B站《全职高手》20万条评论数据
本周我们的目标是:B站(哔哩哔哩弹幕网 https://www.bilibili.com )视频评论数据. 我们都知道,B站有很多号称“镇站之宝”的视频,拥有着数量极其恐怖的评论和弹幕.所以这次我们的 ...
- 精通python网络爬虫之自动爬取网页的爬虫 代码记录
items的编写 # -*- coding: utf-8 -*- # Define here the models for your scraped items # # See documentati ...
- python网络爬虫之四简单爬取豆瓣图书项目
一.爬虫项目一: 豆瓣图书网站图书的爬取: import requests import re content = requests.get("https://book.douban.com ...
- Python爬取招聘信息,并且存储到MySQL数据库中
前面一篇文章主要讲述,如何通过Python爬取招聘信息,且爬取的日期为前一天的,同时将爬取的内容保存到数据库中:这篇文章主要讲述如何将python文件压缩成exe可执行文件,供后面的操作. 这系列文章 ...
- python 网络爬虫(二)
一.编写第一个网络爬虫 为了抓取网站,我们需要下载含有感兴趣的网页,该过程一般被称为爬取(crawling).爬取一个网站有多种方法,而选择哪种方法更加合适,则取决于目标网站的结构. 首先探讨如何安全 ...
- 网络爬虫之scrapy爬取某招聘网手机APP发布信息
1 引言 过段时间要开始找新工作了,爬取一些岗位信息来分析一下吧.目前主流的招聘网站包括前程无忧.智联.BOSS直聘.拉勾等等.有段时间时间没爬取手机APP了,这次写一个爬虫爬取前程无忧手机APP岗位 ...
随机推荐
- ASP.NET Web配置指南
利用ASP.NET,可以指定影响服务器上所有的Web应用程序.仅影响单个的应用程序.影响个别页面.或影响Web应用程序中的个别文件夹的配置设置.可以对编译器选项.调试.用户身份验证.错误消息显示.连接 ...
- 计蒜客 30999 - Sum - [找规律+线性筛][2018ICPC南京网络预赛J题]
题目链接:https://nanti.jisuanke.com/t/30999 样例输入258 样例输出814 题意: squarefree数是指不含有完全平方数( 1 除外)因子的数, 现在一个数字 ...
- Win_Server_2008 安装 Oracle_11g EM时上载EM资料失败
此问题本人也遇到过.在网上找到了解决方案.下部分引用IT PUB. 安装oracle11g 64位.创建数据库到快结束的时候,报告说EM无法创建.emca_2010_06_13_11_05_36.lo ...
- AndroidStudio 3.3+ ButterKnife R2 红名问题
如果你一直用着ButterKnife,但是用的低版本(比如用得很多的8.4.0),然后在多module项目中一定知道要把R改成R2 然后最近如果升级AndroidStudio了,升到3.3以上(201 ...
- 【Python接口测试】简单系统登录接口测试实例
我们可以用Jmeter做接口测试,但是呢个人觉得那个有点局限性,用python就灵活很多, 可以按自己的思路来构建比较灵活,下面给大家介绍一个简单的接口测试实例. 一.我们的思路如下: 首先我们要弄清 ...
- 知道椭圆长轴,短轴长度,ab直线的长度知道且垂直于长轴。求ab的弧长。
1:知道椭圆长轴,短轴长度,ab直线的长度知道且垂直于长轴.求ab的弦长.: https://jingyan.baidu.com/article/a378c960a5af27b3282830e6.ht ...
- 关于Flag的定义
最近在维护项目的代码,发现了由于Flag不一致导致的很多问题,现在对这一问题总结. 1,flag分为两种,可以组合的和不可以组合的.可以组合的flag适合用每一位表示一个含义.不适合组合的flag适合 ...
- python图片处理(二)
未经允许,请勿转载!!!! 这次打算先写处理图片的方法,然后再调用方法来运行 下面先写的是处理图片的方法: # -*- coding: utf-8 -*- import os import matpl ...
- Winter Storm Warning
2019-01-02 11:22:33 ...WINTER STORM WARNING REMAINS IN EFFECT UNTIL 6 AM AKST TUESDAY... * WHAT...He ...
- visual studio 2010 winform程序不能添加对system.web的引用
visual studio 2010 winform程序不能添加对system.web的引用[转载] 需要引用到System.Web.发现没有“System.Web”.在通过“浏览”方式,找到该DLL ...