利用python在windows环境下爬取赶集网工作信息。
主要用到了多进程和多线程的知识,最后结果保存成csv文件格式,如有需要可改成数据库版本。
对用到的库做下简要介绍,具体请参考官方文档:
- xpinyin.Pinyin:将输入的中文转成拼音
- concurrent.futures.ProcessPoolExecutor:多进程
- concurrent.futures.ThreadPoolExecutor:多线程
# -*- coding: utf-8 -*-
# @Author: Studog
# @Date: 2017/5/24 9:27 import requests
import lxml.html as HTML
import csv
from xpinyin import Pinyin
import os
import concurrent.futures class GanjiSpider(object): def __init__(self):
self.city = input("请输入城市名:\n")
p = Pinyin()
city_name = p.get_initials(self.city, '').lower()
self.url = 'http://{0}.ganji.com/v/zhaopinxinxi/p1/'.format(city_name)
self.save_path = r'E:\data\ganji.csv'
file_dir = os.path.split(self.save_path)[0]
if not os.path.isdir(file_dir):
os.makedirs(file_dir)
if not os.path.exists(self.save_path):
os.system(r'echo > %s' % self.save_path) def get_job(self):
flag = True
with open(self.save_path, 'w', newline='') as f:
writer = csv.writer(f)
writer.writerow(['职位名称', '月薪', '最低学历', '工作经验', '年龄', '招聘人数','工作地点'])
while flag:
html = HTML.fromstring(requests.get(self.url).text)
content = html.xpath("//li[@class='fieldulli']/a/@href")
next_page = html.xpath("//li/a[@class='next']/@href")
with concurrent.futures.ProcessPoolExecutor() as executor:
executor.map(self.get_url, content)
if next_page:
self.url = next_page[0]
else:
flag = False def get_url(self, html_page):
html = HTML.fromstring(requests.get(html_page).text)
job_list = html.xpath("//dl[@class='job-list clearfix']/dt/a/@href")
with concurrent.futures.ThreadPoolExecutor() as executor:
executor.map(self.get_info, job_list) def get_info(self, job_url):
html = HTML.fromstring(requests.get(job_url).text)
name = html.xpath("//li[@class='fl']/em/a/text()")
info = html.xpath("//li[@class='fl']/em/text()")[1:]
address = html.xpath(("//li[@class='fl w-auto']/em//text()"))
if name and len(info) == 5 and address:
info[2] = info[2].strip()
address[2] = address[2].strip()
address = ''.join(address)
info.append(address)
name.extend(info)
print(name)
with open(self.save_path, 'a', newline='') as f:
writer = csv.writer(f)
writer.writerow(name) if __name__ == '__main__':
gj = GanjiSpider()
gj.get_job()
利用python在windows环境下爬取赶集网工作信息。的更多相关文章
- Python 爬取赶集网租房信息
代码已久,有可能需要调整 #coding:utf-8 from bs4 import BeautifulSoup #有这个bs4不用正则也可以定位要爬取的内容了 from urlparse impor ...
- Python爬虫基础--分布式爬取贝壳网房屋信息(Client)
1. client_code01 2. client_code02 3. 这个时候运行多个client就可以分布式进行数据爬取.
- Python爬虫基础--分布式爬取贝壳网房屋信息(Server)
1. server_code01 2. server_code02 3. server_code03
- 利用Python编写Windows恶意代码!自娱自乐!勿用于非法用途!
本文主要展示的是通过使用python和PyInstaller来构建恶意软件的一些poc. 利用Python编写Windows恶意代码!自娱自乐!勿用于非法用途!众所周知的,恶意软件如果影响到了他人的生 ...
- 如何利用Xpath抓取京东网商品信息
前几小编分别利用Python正则表达式和BeautifulSoup爬取了京东网商品信息,今天小编利用Xpath来为大家演示一下如何实现京东商品信息的精准匹配~~ HTML文件其实就是由一组尖括号构成的 ...
- Python爬虫项目--爬取自如网房源信息
本次爬取自如网房源信息所用到的知识点: 1. requests get请求 2. lxml解析html 3. Xpath 4. MongoDB存储 正文 1.分析目标站点 1. url: http:/ ...
- Node.js爬虫-爬取慕课网课程信息
第一次学习Node.js爬虫,所以这时一个简单的爬虫,Node.js的好处就是可以并发的执行 这个爬虫主要就是获取慕课网的课程信息,并把获得的信息存储到一个文件中,其中要用到cheerio库,它可以让 ...
- python 基于windows环境的ftp功能
描述: 1.基于备份服务器部署的py程序,将需要备份主机目录下的内容下载至备份服务器(服务端和远端都是windows server 2008) 2.py程序部署在windows服务器,后台运行,基于b ...
- python添加Windows环境变量
1.cmd中添加方式 SET PATH=%PATH%;c:\Program Files (x86)\Wireshark 注:如上代码添加c:\Program Files (x86)\Wireshark ...
随机推荐
- 在PHP中使用全局变量的几种方法
简介 即使开发一个新的大型PHP程序,你也不可避免的要使用到全局数据,因为有些数据是需要用到你的代码的不同部分的.一些常见的全局数据有:程序设定类.数据库连接类.用户资料等等.有很多方法能够使这些数据 ...
- JEECMS站群管理系统-- 标签的配置流程
以cms_content_list为例,首先,每一个标签的声明都是在jeecms-context.xml中进行的, <?xml version="1.0" encoding= ...
- 【frame】找上一层
第一种:window.parent第二种:window.top 貌似两种都行 然后找上一层iframe里面的js函数可以这么写: window.parent.functionName(param1, ...
- WebGL 踩坑系列-1
WebGL 中的一些选项WebGL 中开启颜色混合(透明效果) gl.enable(gl.BLEND); gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALP ...
- plsql窗口列表保持
使用plsql窗口列表保持方法如下: 1.工具——首选项——用户界面——自动保存桌面 选一下此项就保存你当前的窗口布局了,下次启动就不用再设置了. 英语版自己对照.
- jquery日期插件jquery.datePicker参数
1.效果图 2.引入JS.CSS文件 jquery-ui.min.css和jquery-ui.min.js文件 Includes: core.js, widget.js, mouse.js, posi ...
- mysql常用的优化措施
http://www.cnblogs.com/ggjucheng/archive/2012/11/07/2758058.html
- angular解决压缩问题,和传送数据
1.angular解决压缩的方法 var app = angular.module("mk",[]); app.controller("ctrl",['$sco ...
- C++ Knowledge series 4
Programming language evolves always along with Compiler's evolvement The Semantics of Function C++ s ...
- php的yii框架开发总结5
MVC架构之model类: 我的日报系统用到的数据表:tbl_dailyreport表 其中anthor_id是外键,对应tbl_user数据表的主键id,下面是tbl_user表 class Dai ...