大数据实训:python爬取51job+hive数据分析+可视化

本文介绍了一次大数据实训项目,包括使用Python Scrapy爬取51job数据并存储至MongoDB,然后通过Hadoop进行数据处理,使用Hive进行数据分析,并在MySQL中创建数据库进行进一步操作,最后完成数据可视化展示。
摘要由CSDN通过智能技术生成

实训要求

利用python编写爬虫程序,从招聘网站上爬取数据,将数据存入到MongoDB数据库中,将存入的数据作一定的数据清洗后做数据分析,最后将分析的结果做数据可视化。

爬虫部分

爬虫框架为Scrapy
在这里插入图片描述
job

# -*- coding: utf-8 -*-
import scrapy
from job51.items import Job51Item

class QcwySpider(scrapy.Spider):
    name = 'job'
    allowed_domains = ['https://serch.51job.com/']
    start_urls = ['https://search.51job.com/list/000000,000000,0130%252C7501%252C7506%252C7502,01%252C32%252C38,9,99,%2520,2,1.html?lang=c&stype=&postchannel=0000&workyear=99&cotype=99&degreefrom=99&jobterm=99&companysize=99&providesalary=99&lonlat=0%2C0&radius=-1&ord_field=0&confirmdate=9&fromType=&dibiaoid=0&address=&line=&specialarea=00&from=&welfare=']

    def parse(self, response):
        all_urls = response.xpath("//*[@id='resultList']/div[@class='el']/p/span/a/@href").getall()
        for url in all_urls:
            yield scrapy.Request(url, callback=self.parse_html, dont_filter=True)
        next_page = response.xpath("//div[@class='p_in']//li[last()]/a/@href").get()
        if next_page:
            yield scrapy.Request(next_page, callback=self.parse, dont_filter=True)
    def parse_html(self, response):
        item = Job51Item()
        try:
            jobname = response.xpath("//div[@class='cn']/h1/text()").getall()[0]
            salary = response.xpath("//div[@class='cn']//strong/text()").get()
            company = response.xpath("//div[@class='cn']//p[@class='cname']/a[1]/@title").get()
            city = response.xpath("//div[@class='cn']//p[@class='msg ltype']/text()").getall()[0]
            workyear = response.xpath("//div[@class='cn']//p[@class='msg ltype']/text()").getall()[1]
            record = response.xpath("//div[@class='cn']//p[@class='msg ltype']/text()").getall()[2]
            requirements = response.xpath("//div[@class='bmsg job_msg inbox']//text()").getall()
            requirement_str = ""
            for requirement in requirements:
                requirement_str += requirement.strip()
            skill = ""
            keyword = response.xpath("//p[@class='fp'][2]/a/text()").getall()
            for i in keyword:
                skill += i + " "
        except:
            jobname = ""
            salary = ""
            company = ""
            city = ""
            workyear = ""
            record = ""
            requirement_str = ""
            skill = ""
        finally:
            item["jobname"] = jobname
            item["salary"] = salary
            item["company"] = company
            item["city"] = city
            item["workyear"] = workyear
            item["record"] = record
            item["requirement"] = requirement_str
            item["skill"] = skill
        yield item


setting

BOT_NAME = 'job51'

SPIDER_MODULES = ['job51.spiders']
NEWSPIDER_MODULE = 'job51.spiders'

MONGODB_HOST='127.0.0.1'
MONGODB_PORT = 27017
MONGODB_DBNAME = '51job_hive'
MONGODB_DOCNAME = 'job51hive'

DOWNLOAD_DELAY = 1
ROBOTSTXT_OBEY = False

DEFAULT_REQUEST_HEADERS = {
   'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
   'Accept-Language': 'en',
   'User_Agent' :'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36'
}

ITEM_PIPELINES = {
    'job51.pipelines.Job51Pipeline': 300,
}


pipeline

# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html

from scrapy.utils.project 
  • 9
    点赞
  • 80
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
大数据实训是一门综合性实训课程,主要涉及到大数据爬取、存储、分析和可视化。其中,Python是一种高级编程语言,被广泛应用于数据爬取、处理和分析的领域。 在课程中,我们会使用Python来编写爬虫程序,从股票相关的网站或API中获取股票数据。通过分析网站结构和数据接口,我们可以使用Python的各种库和框架来获取股票历史交易数据、实时行情数据等。 一旦我们成功获取了股票数据,我们可以使用Hive这个大数据存储和分析工具来存储和处理这些数据。Hive是基于Hadoop平台的数据仓库工具,可以将结构化和半结构化的数据存储在分布式文件系统中,并使用类SQL语言进行查询和分析。 通过Hive,我们可以对爬取到的股票数据进行各种数据处理和分析操作,例如计算股价涨跌幅、交易量统计、计算股票均线指标等。Hive的强大功能和灵活性使得我们可以根据自己的需求和兴趣来进行数据分析,并从中发现有价值的股票市场信息。 为了更好地展示和传达我们的数据分析结果,课程中还会涉及到可视化工具。可视化是将数据以图表、图形等形式呈现出来,使得数据更具有直观性和易懂性。Python中有很多强大的可视化库和工具,例如Matplotlib、Seaborn和Plotly等,可以帮助我们将股票数据进行可视化展示。 总而言之,大数据实训课程中通过使用Python进行股票数据的爬取、使用Hive进行数据分析和使用可视化工具展示结果,帮助我们掌握大数据处理和分析的技能,同时也使我们能够更好地理解和利用股票市场的信息。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值