爬取拉勾网

# -*- coding: utf-8 -*-
# @Time    : 2017/8/29 15:14
# @Author  : z
# @File    : 拉勾网.py
# @Software: PyCharm

import requests
from urllib.parse import urlencode
from bs4 import BeautifulSoup
import json
import pandas
import time
class LaGou(object):
    def __init__(self,kd='python爬虫'):
        self.url = "https://www.lagou.com/jobs/positionAjax.json?city=%E5%8C%97%E4%BA%AC&needAddtionalResult=false&isSchoolJob=0"
        self.headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36',
                        'Referer':'https://www.lagou.com/jobs/list_python?labelWords=&fromSearch=true&suginput=',
                        'Host':'www.lagou.com'}
        self.kd = kd
        self.list=[]

    def parse_html(self):
        self.list.append(['公司', "福利", '地址', '岗位', '薪资', '发布时间', '学历', '工作经验'])
        for i in range(1, 20):
            self.data = {'kd': self.kd, 'pn': i, 'first': 'true'}
            while True:
                try:
                    response = requests.post(self.url, headers=self.headers, data=self.data).text
                    json_response = json.loads(response)
                    list_all = json_response['content']['positionResult']['result']
                    break
                except:
                    time.sleep(1)
            print('------------------------', i, '-------------------')
            for i in list_all:
                list1 = []
                list1.append(i['companyFullName'])
                list1.append(','.join(i['companyLabelList']))
                list1.append(i['district'])
                list1.append(i['positionName'])
                list1.append(i['salary'])
                list1.append(i['createTime'])
                list1.append(i['education'])
                list1.append(i['workYear'])
                self.list.append(list1)
            self.to_file(self.list)
    def to_file(self,list):
        pd = pandas.DataFrame(self.list)
        pd.to_excel('gg.xls')




if __name__ == '__main__':
LaGou().parse_html()
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值