【爬虫相关】爬虫爬取拉勾网的安卓招聘信息

来源:互联网 发布:不知道自己做什么知乎 编辑:程序博客网 时间:2024/04/28 16:03

我爬取了30页拉勾上安卓的招聘数据告诉你 安卓岗位究竟要一个什么样的人

疑问


我知道没图你们是不会看的

大笑



如图:以上是抓取了30页拉勾上关于招聘安卓相关的内容 然后根据词频 制作出词云图  出现最多的词是 开发经验

整体流程总共分为2步

1.爬虫爬取相关的招聘信息

2.根据获取到的招聘信息 生成词云图

这里的爬虫采用的是scrapy框架  编辑器使用的是PyCharm,本次不是针对零基础,如果对爬虫感兴趣推荐大家看这本 我就是看的这本书

链接:爬虫书籍的链接

先对拉勾网的数据进行分析 发现其中链接的规律:

变化的是2 也就是页数


随便点进去一个条目 又发现了这样的规律



找到规律后 核心代码也就是2个正则表达式:

class LagouspiderSpider(scrapy.Spider):    name = 'lagouspider'    allowed_domains = ['www.lagou.com']    start_urls = ['http://www.lagou.com/']    def start_requests(self):        for i in range(2,30):            yield scrapy.Request(url='https://www.lagou.com/zhaopin/Android/'+str(i)+'/?filterOption=3')    def parse(self, response):        string = str(response.body)        # print string        pattern=r'https://www.lagou.com/jobs.\d*?.html'        result=re.findall(pattern=pattern,string=string)        for url in result:            print url            yield scrapy.Request(url=url,callback=self.parse_info)    def parse_info(self,response):        strZhiwei=response.css('.job_bt div').extract()[0]        strZhiwei=strZhiwei.encode('utf-8')        if os.path.exists('lagou.txt'):            f=open('lagou.txt','ab')            f.write(strZhiwei)            f.close()        else:            f=open('lagou.txt','wb')            f.write(strZhiwei)            f.close()
然后把获取到的信息保存到本地 格式是txt格式


然后下载第三方词云的库 生成词云图的核心代码

# -*- coding: utf-8 -*-from os import pathfrom PIL import Imageimport numpy as npimport matplotlib.pyplot as pltimport jiebaimport refrom wordcloud import WordCloud, STOPWORDS, ImageColorGeneratord = path.dirname(__file__)# Read the whole text.text = open(path.join(d, 'lagou.txt')).read().decode('utf-8')# read the mask / color image taken from# hp://jirkavinse.deviantart.com/art/quot-Real-Life-quot-Alice-282261010alice_coloring = np.array(Image.open(path.join(d, "a.png")))stopwords = set(STOPWORDS)stopwords.add("said")# wc = WordCloud(font_path=font,background_color="white", max_words=2000, mask=alice_coloring,#                stopwords=stopwords, max_font_size=40, random_state=42, )# generate word cloudwc = WordCloud(                background_color = 'white',    # 设置背景颜色                mask = alice_coloring,        # 设置背景图片                max_words = 7000,            # 设置最大显示的字数                font_path = 'AdobeHeitiStd-Regular.otf',# 设置字体格式,如不设置显示不了中文                max_font_size = 95,            # 设置字体最大值                random_state = 100,            # 设置有多少种随机生成状态,即有多少种配色方案                )def stop_words(texts):    words_list = []    words_list = jieba.cut(texts, cut_all=False)  # 返回的是一个迭代器    return ' '.join(words_list)  # 注意是空格text = stop_words(text)wc.generate(text)# create coloring from imageimage_colors = ImageColorGenerator(alice_coloring)# showplt.imshow(wc, interpolation="bilinear")plt.axis("off")plt.figure()# recolor wordcloud and show# we could also give color_func=image_colors directly in the constructorplt.imshow(wc.recolor(color_func=image_colors), interpolation="bilinear")plt.axis("off")plt.figure()plt.imshow(alice_coloring, cmap=plt.cm.gray, interpolation="bilinear")plt.axis("off")plt.show()wc.to_file("zq——zjl.jpg")


当然 同样找规律 更改相关的链接可以爬取其他岗位 的招聘信息,或者重写正则表达式 获取其他自己需要的内容

注意:如果请求的次数过多 拉勾 会有反爬虫的相关措施,比如封禁ip

解决方案会在下次更新

代码下载链接

代码下载,地球人都说好








阅读全文
'); })();
0 0
原创粉丝点击
热门IT博客
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 婚宴祝酒词 举办婚宴 喜来登酒店婚宴价格 创意婚宴 婚宴上用什么酒 金钱豹婚宴价格 婚宴上的讲话 现在婚宴多少钱一桌 婚宴喝什么酒 全聚德婚宴价格 婚宴宴会厅 湖东一号婚礼喜宴会所 婚宴酒席菜单 五星酒店婚宴价格 婚宴报价 婚宴多少钱一桌 梦见参加婚礼吃喜宴 回想那一天喧闹的喜宴 喜帖 喜帖街 喜帖街歌词 喜帖街 歌词 喜帖 图片 喜帖街琴谱 喜帖街下载 喜帖街吉他谱 喜帖街粤语发音 喜帖街的意思 喜帖街铃声下载 喜帖街谐音歌词 喜贴 微喜帖 微请柬 结婚请帖怎么写 新婚致词 在线制作漂亮喜帖 请柬 婚礼请帖怎么写 请柬电子版 电子请帖制作软件 电子请柬