没有网络怎么学网络爬虫之爬取智联招聘网python就业招聘信息存入Excel表格

没有网络可以练习网络爬虫?当然可以啦,但是必须先找个有网络的地方,打开你要爬取的网页,找的你要获取的内容,我将要在智联招聘网上获取招聘python的相关信息,如(工作名称、公司名称、薪资待遇、地址、经验、学历、公司性质、招聘人数、公司福利等)

1、爬虫前步骤

(1)找个有网的地方,打开需要爬取网页。
(2)找到需要获取的内容。
在这里插入图片描述
(3)保存源码到本地文件,我们没有必要全部保存,最好选取需要的部分进行保存,智联招聘网python有两页,我把它一起保存在G:/20190720_zhilianzhaopin.html中,可以直接复制粘贴需要部分。
在这里插入图片描述
(4)新建记事本,ctrl+v粘贴刚复制的内容

<html>
<head>
<title>智联招聘网python信息</title>
</head>
<body>
这里是复制进来的内容,可以多个页面和为一个html

</body>
</html>

(5)现在直接访问本地文件了,想去哪里玩爬虫都可以了,无需网络!!!
在这里插入图片描述

2、爬取网页代码

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import urllib2
from bs4 import BeautifulSoup
import xlwt

url = 'file:///G:/20190720_zhilianzhaopin.html'#本地网页路径
html = urllib2.urlopen(url).read()
soup = BeautifulSoup(html,"html.parser")
all_page=[]

#爬虫函数
for tag in soup.find_all(attrs = {"class":"contentpile__content__wrapper__item clearfix"}):
    print u'工作名称:',tag.span.get('title')
    gzmc = tag.span.get('title')
    
    for d in tag.find_all(attrs = {"class":"contentpile__content__wrapper__item__info__box__cname__viplevel is_vipLevel"}):
        print u'公司名称:',d.get('alt')
        gsmc = d.get('alt')
        
    for p in tag.find_all(attrs = {"class":"contentpile__content__wrapper__item__info__box__job__saray"}):
        print u'薪资待遇:',p.get_text()
        xzdy = p.get_text()

    #公司要求
    for ul in tag.find_all(attrs = {"class":"contentpile__content__wrapper__item__info__box__job__demand"}):
        print u'地址:',ul.find_all('li')[0].get_text()
        print u'经验:',ul.find_all('li')[1].get_text().replace("\n","").replace(" ","")
        print u'学历:',ul.find_all('li')[-1].get_text()
        dz = ul.find_all('li')[0].get_text()
        jl = ul.find_all('li')[1].get_text().replace("\n","").replace(" ","")
        xl = ul.find_all('li')[-1].get_text()

    for comdec in tag.find_all(attrs = {"class":"contentpile__content__wrapper__item__info__box__job__comdec"}):
        print u'公司性质:',comdec.find_all('span')[0].get_text()
        print u'招聘人数:',comdec.find_all('span')[-1].get_text()
        gsxz = comdec.find_all('span')[0].get_text()
        zprs = comdec.find_all('span')[-1].get_text()
        
    for welfare in tag.find_all(attrs = {"class":"contentpile__content__wrapper__item__info__box__welfare job_welfare"}):
        print u'公司福利:',welfare.get_text()
        gsfl = welfare.get_text()
        print " "
        
    page = [gzmc,gsmc,xzdy,dz,jl,xl,gsxz,zprs,gsfl]
    all_page.append(page)

    book = xlwt.Workbook(encoding='utf-8')
    sheet = book.add_sheet('python就业情况表')
    head = ['工作名称','公司名称','薪资待遇','地址','经验','学历','公司性质','招聘人数','公司福利']
    for h in range(len(head)):
        sheet.write(0,h,head[h])

    j = 1
    for list in all_page:
        k = 0
        for data in list:
            sheet.write(j,k,data)
            k = k+1
        j = j+1
    book.save('D:/Python/智联招聘python就业公司情况.xls') 

运行结果:
在这里插入图片描述
Excel结果:
在这里插入图片描述

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
好的,您想要了解如何使用 Python 爬取智联招聘站上的工作岗位信息对吗? 首先,我们可以使用 Python 中的 requests 库来向智联招聘站发送 HTTP 求,从而获取页面内容。然后,我们可以使用 BeautifulSoup 库来解析页面内容,提取出我们需要的信息。 以下是一个示例代码,用于爬取智联招聘站上的 Python 工程师工作岗位信息: ```python import requests from bs4 import BeautifulSoup url = 'https://fe-api.zhaopin.com/c/i/sou?pageSize=60&cityId=489&salary=0,0&workExperience=-1&education=-1&companyType=-1&employmentType=-1&jobWelfareTag=-1&kw=Python&kt=3&_v=0.97530866&x-zp-page-request-id=ad1b5d3b9e3b4d2d9f0f0e6fcb3f8c1d-1626242840263-285644' headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299' } response = requests.get(url, headers=headers) soup = BeautifulSoup(response.content, 'html.parser') job_list = soup.find_all('div', {'class': 'job-list'}) for job in job_list: job_name = job.find('a', {'target': '_blank', 'data-jid': True}).text.strip() job_salary = job.find('span', {'class': 'salary'}).text.strip() job_company = job.find('a', {'class': 'company-name'}).text.strip() job_location = job.find('span', {'class': 'job-area'}).text.strip() job_experience = job.find('span', {'class': 'job-exp'}).text.strip() print(job_name, job_salary, job_company, job_location, job_experience) ``` 在这个示例代码中,我们使用了 requests 库向智联招聘站发送了一个 HTTP 求,并设置了求头部信息,以避免被站识别为爬虫。然后,我们使用 BeautifulSoup 库解析了页面内容,并从中提取出了工作岗位信息。 您可以根据自己的需求修改代码中的参数和条件,以获得您需要的工作岗位信息。注意,爬取信息时要遵守相关法律法规和站规定,不要过度频繁地站,以免对站造成影响。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值