加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

Python爬虫遇上FineBI画图!这就是黑科技的力量!

发布时间:2020-12-17 01:17:14 所属栏目:Python 来源:网络整理
导读:p style="margin:10px auto;color:rgb(57,57,57);font-family:verdana,'ms song',Arial,Helvetica,sans-serif;font-size:14px;text-align:left;background-color:rgb(250,247,239);"我们平时在用Python爬取网页上的数据时,对爬取到到的数据做数据分析展现有

<p style="margin:10px auto;color:rgb(57,57,57);font-family:verdana,'ms song',Arial,Helvetica,sans-serif;font-size:14px;text-align:left;background-color:rgb(250,247,239);">我们平时在用Python爬取网页上的数据时,对爬取到到的数据做数据分析展现有很多种方式,比如可以通过echart图表接口、python提供的第三方库,甚至还可以用matlab工具来进行数据统计和图表可视化展现。

<p style="margin:10px auto;color:rgb(57,239);">可无论是以上哪一种方式,都需要通过代码来调用Python爬好的数据来进行画图,图表样式属性设置等方面还是比较繁琐的。

<p style="margin:10px auto;color:rgb(57,239);">同样的问题,有一次小编领导要求我做一份有关于南京房价的数据汇报,需要做到报表里面。数据是没有的,自然而然想到用Python爬,爬好后直接做数据图表粘贴到报表中。但后来发现方法太土,汇报时不好做动态的数据展现(影响小编炫技装逼)。于是乎就想办法,将爬取到的数据导入到报表或者BI系统里面,利用BI本身的一些分析功能,联动着其他数据做展现。于是就有了本篇“Python爬数据,FineBI画图”的文章。

<h2 style="margin-top:10px;margin-bottom:10px;padding:0px;font-size:21px;line-height:1.5;color:rgb(57,sans-serif;text-align:left;background-color:rgb(250,239);">关于FineBI<p style="margin:10px auto;color:rgb(57,239);">这是一个可视化的自助式BI工具,整个操作就是导数据/连数据库——处理数据(可视化ETL)选择图表——拖数据字段——可视化展现&美化,操作简单上手快。小编只是用了其可视化的一隅功能,多数情况下,这个工具都是拿来做可视化报表,对接企业大数据平台,做企业数据运营分析用。

<h2 style="margin-top:10px;margin-bottom:10px;padding:0px;font-size:21px;line-height:1.5;color:rgb(57,239);">原理介绍<p style="margin:10px auto;color:rgb(57,239);">废话不多说,直接贴出操作。

<p style="margin:10px auto;color:rgb(57,239);">因为想看看南京房价数据,但是网站上的很多数据都是以HTM5的形式进行呈现的,所以考虑通过Python来进行网页数据抓取和入库,数据分析方面通过FineBI工具直接连接数据库,分析和可视化呈现。

<h4 style="margin-top:10px;margin-bottom:10px;padding:0px;font-size:14px;color:rgb(51,51,51);font-family:verdana,239);">整体的思路:<p style="margin:10px auto;color:rgb(57,239);">数据层方面先通过Python抓取到WEB端的网页数据,之后对爬取到数据进行解析再而存储到MYSQL数据入库;

<p style="margin:10px auto;color:rgb(57,239);">最后应用层的数据处理、数据计算统计、图表可视化呈现等工作全都交由FineBI工具来做。

<p style="margin:10px auto;color:rgb(57,239);">

<h2 style="margin-top:10px;margin-bottom:10px;padding:0px;font-size:21px;line-height:1.5;color:rgb(57,239);">操作步骤<h4 style="margin-top:10px;margin-bottom:10px;padding:0px;font-size:14px;color:rgb(51,239);">1.引入相关python库包<p style="margin:10px auto;color:rgb(57,239);">首先新建python工程,引入本次爬取网页数据和写入MySQL数据库所需要的requests、pymysql、bs4这三个包:

<p style="margin:10px auto;color:rgb(57,239);">

<h4 style="margin-top:10px;margin-bottom:10px;padding:0px;font-size:14px;color:rgb(51,239);">2.获取网页数据<p style="margin:10px auto;color:rgb(57,239);">然后如下图所示,通过编写Python代码获取到某一个房产网页的南京售房平台的网页信息:

<p style="margin:10px auto;color:rgb(57,239);">

<h4 style="margin-top:10px;margin-bottom:10px;padding:0px;font-size:14px;color:rgb(51,239);">3.HTML标签解析<p style="margin:10px auto;color:rgb(57,239);">接着再对DIV样式下的HTML数据包进行逐一解析,获取到想要的房源名称、地址、小区、户型、面积、总价、单价、区域等数据:

<p style="margin:10px auto;color:rgb(57,239);">

<p style="margin:10px auto;color:rgb(57,239);">其中对应网页的标签样式可以通过浏览器的F12开发选项进行快速获取,如下图所示的定位房源信息截图,我们只需要右键浏览器在所需要获取标签样式名称的地方点击检查元素即可(房源名称的标签即位house-title的title元素)。

<p style="margin:10px auto;color:rgb(57,239);">

<h4 style="margin-top:10px;margin-bottom:10px;padding:0px;font-size:14px;color:rgb(51,239);">4.MySQL数据回写<p style="margin:10px auto;color:rgb(57,239);">解析好数据之后,再将解析好的数据写入到MySQL数据库中:

<p style="margin:10px auto;color:rgb(57,239);">

<p style="margin:10px auto;color:rgb(57,239);">循环遍历该平台在南京最近七天的网页售房信息数据,页面17页,共计377条数据:

<p style="margin:10px auto;color:rgb(57,239);">

<h4 style="margin-top:10px;margin-bottom:10px;padding:0px;font-size:14px;color:rgb(51,239);">5.安装FineBI&&验证数据入库<p style="margin:10px auto;color:rgb(57,239);">通过FineBI官网下载并按照引导安装好软件:

<p style="margin:10px auto;color:rgb(57,239);">

<p style="margin:10px auto;color:rgb(57,239);">直接通过FineBI提供的数据配置端的功能,添加SQL数据集(或者直接添加表也行),查看和验证刚刚爬取并且入库的数据是否已经真正成功入库到MySQL中了。

<p style="margin:10px auto;color:rgb(57,239);">如下图所示,Python果然不辱使命,我要的该平台的七天南京的房价售房数据都已经成功写入到了我的MySQL数据库中了。

<p style="margin:10px auto;color:rgb(57,239);">

<h4 style="margin-top:10px;margin-bottom:10px;padding:0px;font-size:14px;color:rgb(51,239);">6.FineBI可视化制作&成果展示<p style="margin:10px auto;color:rgb(57,239);">然后思考需要分析展现哪些内容,比如“南京各小区房价分布”、“房型价格分析”、“各区域房价分析”.....通过FineBI制作图表展现。

<p style="margin:10px auto;color:rgb(57,239);">下面这个动图展示了一个图表的制作,其他都类似的,可参考。不懂可参见FineBI官网的帮助文档。

<p style="margin:10px auto;color:rgb(57,239);">

<p style="margin:10px auto;color:rgb(57,239);">花了十分钟,就将我想要看的南京售房信息(房源面积均价、套房总均价、小区房价四象限分布图、区域房价分析、房型价格分析)以可视化的形式呈现出来了。

<p style="margin:10px auto;color:rgb(57,239);">最后就是本次成果展示啦,也晒出来跟大家分享下,如下所示:

<p style="margin:10px auto;color:rgb(57,239);">

<p style="margin:10px auto;color:rgb(57,239);">1.目前南京房源均价为3.78万每平方米,总均价为401.38万,总体上还是比较高的。

<p style="margin:10px auto;color:rgb(57,239);">2.建邺区房价最高,果然房价还是紧跟国家政策啊,建邺目前城区开发建设政府的扶持力度在南京都是走在前面的。鼓楼、玄武、秦淮分别排在二、三、四的位置,雨花台和江宁房价相对较低,综合市区位置来看,还是秦淮区性价比最高啊 。

<p style="margin:10px auto;color:rgb(57,239);">3.房型方面,6室3厅的豪华大宅总均价接近一千万,比如紫檀雅居、碧水湾别墅、滨江奥城听雨苑这一类土豪小区,多集中在建邺和鼓楼区域;一室一厅的房子均价大概在150万的样子,比如托乐嘉单身公寓、经纬城市花园等小区,适合单身贵族或者情侣小夫妇居住,南京各个大区都有;比较主流的三室一厅房价在300万左右,比如乔虹苑小区、良辰美景家园、白云园,多集中在秦淮和鼓楼区域。

<h2 style="margin-top:10px;margin-bottom:10px;padding:0px;font-size:21px;line-height:1.5;color:rgb(57,239);">后记<p style="margin:10px auto;color:rgb(57,239);">Python完成对网页数据的抓取和解析存储之后,配合FineBI强大的数据可视化呈现能力则圆满地完成了本次对南京售房数据的统计和分析需求,绝对推荐!

<p style="margin:10px auto;color:rgb(57,239);">欢迎关注我的博客或者公众号哦:https://home.cnblogs.com/u/Python1234/ ? ? ? ? ? ?Python学习交流

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读