利用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函数内不能访问函数外的变量原因
执行如下代码: $i = 10; function my(){ echo $i; } my(); xdebug显示是:Undefined variable 以前也知道有这个问题存在,即函数内部不可以访 ...
- Emacs学习笔记2
emacs的启动初始化 需要有一个~/.emacs文件, 这个和vim一样 emacs中的查找与替换 递增查找 C-s, 在minibuffer中输入即可, 在一次C-s会跳转到下一个 两次C-g取消 ...
- Intellij IDEA +genymotion安装配置
Intellij IDEA是一款非常好用的java编辑器,比Eclipse的代码提示要友善的多,优缺点不多讲了. 下面讲如何安装配置. 1)如官网下载最新版本 http://www.jetbrains ...
- 设计模式在Spring
设计模式在spring中的使用1.工厂模式,这个很明显,在各种BeanFactory以及ApplicationContext创建中都用到了:2.模版模式,这个也很明显,在各种BeanFactory以及 ...
- 服务器断电后 redis重启后启动不起来
服务器断电后 redis 重启后启动不起来 原因:db持久化失败 1. 先查询redis的进程 ps -ef|grep redis 2. 查询redis的缓存文件在哪 whereis dump.rdb ...
- mysql关键字执行顺序
from on join where group by having select distinct union order by 昨天去58面试,之前的java基础和数据结构算法之类的都还可以,最后 ...
- centos6 hadoop2.7.3分布式搭建
一.hadoop下载 apache所有的project都有自己的域名,可以通过apache官网下的project list去找,也可以直接定位project.apache.org,比如hadoop直接 ...
- The fifth day
All men cannot be first . 今日单词: first(形容词):第一的:基本的:最早的:(副词):第一:首先 翻译:不可能人人都是第一名. <Only Love>-- ...
- 切图让我进步!关于white-space属性的组合拳
菜鸟一枚,没有大神的风骚,只有一点在练习中的心得,今天获得的知识是关于white-space属性.overflow属性还有text-overflow属性的组合使用,废话不多说浪费时间,进入今天的正题! ...
- polyfill 一个解决兼容的绝佳方案
polyfill为何物 Polyfill你可以理解为“腻子”,就是装修的时候,可以把缺损的地方填充抹平. 举个例子,html5的storage(session,local), 不同浏览器,不同版本,有 ...