1. 程式人生 > >python實現數據爬取-清洗-持久化存儲-數據平臺可視化

python實現數據爬取-清洗-持久化存儲-數據平臺可視化

爬蟲 python 數據分析 數據清理 數據挖掘

基於python對淘寶模特個人信息進行篩選爬取,數據清洗,持久化寫入mysql數據庫.使用django對數據庫中的數據信息篩選並生成可視化報表進行分析。


數據爬取,篩選,存庫:

# -*- coding:utf-8 -*-
 
import requests
from bs4 import BeautifulSoup
import sys
import re
reload(sys)
sys.setdefaultencoding(‘utf-8‘)
import MySQLdb
import chardet

conn= MySQLdb.connect(
        host=‘localhost‘,
        port = 數據庫端口,
        user=‘root‘,
        passwd=‘數據庫密碼
        db =‘xxnlove‘,
	charset=‘utf8‘
        )
cur = conn.cursor()
cur.execute("create table model(name text(225),age varchar(10),blood varchar(10),school text(225),height varchar(10),weight varchar(10),Measurements text(225),cup varchar(20),location text(225))ENGINE=InnoDB DEFAULT CHARSET=utf8;")

#CREATE DATABASE gmtdb DEFAULT CHARACTER SET utf8mb4;
for num in range(521,1314):
    try:
        URL = ‘http://mm.taobao.com/json/request_top_list.htm?page=%d‘ % num
        #print "現在爬取的網站url是:" + URL
        response = requests.get(URL) 
        response.encoding = ‘gb2312‘
        text = response.text 
        soup = BeautifulSoup(text, ‘lxml‘) 
        for model in soup.select(".list-item"):
            try:
                model_id =  model.find(‘span‘, {‘class‘: ‘friend-follow J_FriendFollow‘})[‘data-userid‘]
                json_url = "http://mm.taobao.com/self/info/model_info_show.htm?user_id=%d" % int(model_id)
                response_json = requests.get(json_url)
                response_json.encoding = ‘gb2312‘
                text_response_json = response_json.text
                soup_json = BeautifulSoup(text_response_json, ‘lxml‘)
                
                #print "***********************************" + model.find(‘a‘, {‘class‘: ‘lady-name‘}).string + "*********************************"
                #print "模特的名字:" + model.find(‘a‘, {‘class‘: ‘lady-name‘}).string
                name = model.find(‘a‘, {‘class‘: ‘lady-name‘}).string
                #print "模特的年齡:"+ model.find(‘p‘, {‘class‘: ‘top‘}).em.strong.string
		age =  model.find(‘p‘, {‘class‘: ‘top‘}).em.strong.string
		blood =  soup_json.find_all(‘li‘, {‘class‘: ‘mm-p-cell-right‘})[1].span.string		
               # if blood is None:
               #     blood = "None"
		school = soup_json.find_all(‘li‘)[5].span.string
		height = soup_json.find(‘li‘, {‘class‘: ‘mm-p-small-cell mm-p-height‘}).p.string
		weight = soup_json.find(‘li‘, {‘class‘: ‘mm-p-small-cell mm-p-weight‘}).p.string
		Measurements = soup_json.find(‘li‘, {‘class‘: ‘mm-p-small-cell mm-p-size‘}).p.string
		location = model.find(‘p‘, {‘class‘: ‘top‘}).span.string
		cup =  soup_json.find(‘li‘, {‘class‘: ‘mm-p-small-cell mm-p-bar‘}).p.string
		sqli="insert into model values(%s,%s,%s,%s,%s,%s,%s,%s,%s)"
		cur.execute(sqli,(name,age,blood,school,height,weight,Measurements,cup,location))
                #print "罩杯:" + soup_json.find(‘li‘, {‘class‘: ‘mm-p-small-cell mm-p-bar‘}).p.string
                ‘‘‘
                print "生日:" + soup_json.find(‘li‘, {‘class‘: ‘mm-p-cell-left‘}).span.string
                blood =  soup_json.find_all(‘li‘, {‘class‘: ‘mm-p-cell-right‘})[1].span.string
                if blood is None:
                    blood = "無"
                print "血型:" + blood
                print "學校/專業:" + soup_json.find_all(‘li‘)[5].span.string
                print "身高:" + soup_json.find(‘li‘, {‘class‘: ‘mm-p-small-cell mm-p-height‘}).p.string
                print "體重:" + soup_json.find(‘li‘, {‘class‘: ‘mm-p-small-cell mm-p-weight‘}).p.string
                print "三圍:" + soup_json.find(‘li‘, {‘class‘: ‘mm-p-small-cell mm-p-size‘}).p.string
                print "罩杯:" + soup_json.find(‘li‘, {‘class‘: ‘mm-p-small-cell mm-p-bar‘}).p.string
                print "鞋碼:" + soup_json.find(‘li‘, {‘class‘: ‘mm-p-small-cell mm-p-shose‘}).p.string
                print "模特所在地:"+ model.find(‘p‘, {‘class‘: ‘top‘}).span.string
                print "模特的id:"+ model.find(‘span‘, {‘class‘: ‘friend-follow J_FriendFollow‘})[‘data-userid‘]
                print "模特的標簽:"+ model.find_all(‘p‘)[1].em.string
                print "模特的粉絲數:"+ model.find_all(‘p‘)[1].strong.string
                print "模特的排名:"+ [text for text in model.find(‘div‘, {‘class‘: ‘popularity‘}).dl.dt.stripped_strings][0]
                print model.find(‘ul‘, {‘class‘: ‘info-detail‘}).get_text(" ",strip=True)
                print "模特的個人資料頁面:" +"http:"+ model.find(‘a‘, {‘class‘: ‘lady-name‘})[‘href‘]			             		
                print "模特的個人作品頁面:" +"http:"+ model.find(‘a‘, {‘class‘: ‘lady-avatar‘})[‘href‘]
                print "模特的個人頭像:" + "http:" + model.find(‘img‘)[‘src‘]
                print "***********************************" + model.find(‘a‘, {‘class‘: ‘lady-name‘}).string + "*********************************"
                print "\n"
		‘‘‘
            except:
                print "error"
    except:
        print num + "page is error"
cur.close()
conn.commit()
conn.close()

數據庫結構:

技術分享

寫入數據庫中的模特記錄數量:

技術分享

寫入數據庫中模特信息部分圖:

技術分享


django 實現圖表展示:

#coding:utf-8
# Create your views here.
from django.shortcuts import render,render_to_response
from django.http import HttpResponse,HttpResponseRedirect
import MySQLdb
import sys
import re
import json
import jieba
from operator import itemgetter
from pytagcloud import create_tag_image, make_tags
import random
import time 
import smtplib
from email.mime.text import MIMEText
reload(sys)
sys.setdefaultencoding(‘utf-8‘)
conn= MySQLdb.connect(
        host=‘localhost‘,
        port = 端口,
        user=‘root‘,
        passwd=‘密碼‘,
        db =‘xxnlove‘,
	    charset=‘utf8‘
        )
def receive_message(request):
    if request.method == ‘POST‘:
        name = request.POST[‘name‘]
        email = request.POST[‘email‘]
        subject = request.POST[‘subject‘]
        message = request.POST[‘message‘]
        cur = conn.cursor()
        sql = "insert into message values(%s,%s,%s,%s)"
        cur.execute(sql,(name,email,subject,message))
        cur.close()
        conn.commit()
        conn.close()  
        return render_to_response(‘index.html‘)   

def send_email(request):
    _user = "[email protected]
/* */" _pwd = "**************" _to = "[email protected]" msg = MIMEText("Test") msg["Subject"] = "don‘t panic" msg["From"] = _user msg["To"] = _to try: s = smtplib.SMTP_SSL("smtp.qq.com", 465) s.login(_user, _pwd) s.sendmail(_user, _to, msg.as_string()) s.quit() return HttpResponse("郵件發送成功") except smtplib.SMTPException,e: return HttpResponse("Falied,%s"%e ) def create_pictures(request): cur = conn.cursor() sql = "select school from model " cur.execute(sql) rows = cur.fetchall() cur.close() conn.commit() conn.close() fclist = [] for row in rows: fclist.append(row[0].encode("utf-8")) fcstr = " ".join(fclist) wg = jieba.cut_for_search(fcstr) wd = {} nonsense = [u"我的", u"什麽", u"你好"] for w in wg: if len(w) < 2: continue elif w in nonsense: continue try: str(w) continue finally: if w not in wd: wd[w] = 1 else: wd[w] += 1 swd = sorted(wd.iteritems(), key=itemgetter(1), reverse=True) swd = swd[1:100] tags = make_tags(swd,maxsize = 100) create_tag_image(tags, ‘./modles/static/1.jpg‘, #background=(0, 0, 0, 255), size=(500, 300), fontname="STKAITI") # cur.close() # conn.commit() # conn.close() return render(request,‘index.html‘) def cloud(request): return render(request,‘cloud.html‘) def index(request): return render(request,‘index.html‘) def search(request): if request.method == ‘POST‘: modelname = request.POST[‘name‘] sql = "select * from model where name=‘%s‘" % modelname cur = conn.cursor() try: search = cur.execute(sql) info = cur.fetchmany(search) name = info[0][0] age = info[0][1] school = info[0][3] school = ‘‘.join(school.split()) height = info[0][4] weight = info[0][5] Measurements = info[0][6] return render(request, ‘index.html‘, {‘name‘: name,‘age‘: age,‘school‘:school,‘height‘:height,‘weight‘:weight,‘Measurements‘:Measurements}) except: prompt = "sorry: 數據庫中沒有 "+modelname+" 這個模特的信息" return render(request, ‘index.html‘, {‘prompt‘: prompt}) cur.close() conn.commit() conn.close() else: return HttpResponse(‘提交的方式不是post‘) def show(request): cur = conn.cursor() agedata = [] category = [] for i in range(10,40): category.append(i) age = i sql = "select count(*) from model where age=‘%s‘" % age age = cur.execute(sql) i = int(cur.fetchmany(age)[0][0]) agedata.append(i) return render(request,‘show.html‘,{‘category‘:category,‘agedata‘:agedata}) cur.close() conn.commit() conn.close() def area(request): cur = conn.cursor() citydict = {‘jianxi‘:‘南昌市|贛州市|上饒市|吉安市|九江市|新余市|撫>州市|宜春市|景德鎮市|萍鄉市|鷹潭市|江西‘, ‘beijin‘:‘北京‘, ‘guangdong‘:‘東莞市|廣州市|中山市|深圳市|惠州市|江門市|珠海市|汕頭市|佛山市|湛江市|河源市|肇慶市|清遠市|潮州市|韶關市|揭陽市|陽江市|梅州市|雲浮市|茂名市|汕尾市|廣東‘, ‘shandong‘:‘濟南市|青島市|臨沂市|濟寧市|菏澤市|煙臺市|淄博市|泰安市|濰坊市|日照市|威海市|濱州市|東營市|聊城市|德州市|萊蕪市|棗莊市|山東‘, ‘jiangsu‘:‘蘇州市|徐州市|鹽城市|無錫市|南京市|南通市|連雲港市|常州市|鎮江市|揚州市|淮安市|泰州市|宿遷市‘, ‘henan‘:‘鄭州市|南陽市|新鄉市|安陽市|洛陽市|信陽市|平頂山市|周口市|商丘市|開封市|焦作市|駐馬店市|濮陽市|三門峽市|漯河市|許昌市|鶴壁市|濟源市|河南‘, ‘shanghai‘:‘松江區|寶山區|金山區|嘉定區|南匯區|青浦區|>浦東新區|奉賢區|徐匯區|靜安區|閔行區|黃浦區|楊浦區|虹口區|普陀區|閘北區|長寧區|崇明縣|盧灣區|上海‘, ‘hebei‘: ‘石家莊市|唐山市|保定市|邯鄲市|邢臺市|河北區|滄州市|秦皇島市|張家口市|衡水市|廊坊市|承德市|河北‘, ‘zhejiang‘:‘溫州市|寧波市|杭州市|臺州市|嘉興市|金華市|>湖州市|紹興市|舟山市|麗水市|衢州市|浙江‘, ‘shanxi‘:‘西安市|鹹陽市|寶雞市|漢中市|渭南市|安康市|榆>林市|商洛市|延安市|銅川市|陜西‘, ‘hunan‘:‘長沙市|邵陽市|常德市|衡陽市|株洲市|湘潭市|永州市|嶽陽市|懷化市|郴州市|婁底市|益陽市|張家界市|湘西州|湖南‘, ‘chongqing‘:‘江北區|渝北區|沙坪壩區|九龍坡區|萬州區|永川市|南岸區|酉陽縣|北碚區|涪陵區|秀山縣|巴南區|渝中區|石柱縣|忠縣|合川市|大渡口區|開縣|長壽區|榮昌縣|雲陽縣|梁平縣|潼南縣|江津市|彭水縣|綦江縣|璧山縣|黔江區|大足縣|巫山縣|巫溪縣|墊江縣|豐都縣|武隆縣|萬盛區|銅梁縣|南川市|奉節縣|雙橋區|城口縣|重慶‘, ‘fujian‘:‘漳州市|廈門市|泉州市|福州市|莆田市|寧德市|三明市|南平市|龍巖市|福建‘, ‘tianjin‘:‘和平區|北辰區|河北區|河西區|西青區|津南區|東麗區|武清區|寶坻區|紅橋區|大港區|漢沽區|靜海縣|塘沽區|寧河縣|薊縣|南開區|河東區|天津‘, ‘yunnan‘:‘昆明市|紅河州|大理州|文山州|德宏州|曲靖市|昭通市|楚雄州|保山市|玉溪市|麗江地區|臨滄地區|思茅地區|西雙版納州|怒江州|迪慶州|雲南‘, ‘sichuan‘:‘成都市|綿陽市|廣元市|達州市|南充市|德陽市|廣安市|阿壩州|巴中市|遂寧市|內江市|涼山州|攀枝花市|樂山市|自貢市|瀘州市|雅安市|宜賓市|資陽市|眉山市|甘孜州|四川‘, ‘guangxi‘:‘貴港市|玉林市|北海市|南寧市|柳州市|桂林市|梧州市|欽州市|來賓市|河池市|百色市|賀州市|崇左市|防城港市|廣西‘, ‘anhui‘:‘安徽|蕪湖市|合肥市|六安市|宿州市|阜陽市|安慶市|馬鞍山市|蚌埠市|淮北市|淮南市|宣城市|黃山市|銅陵市|亳州市|池州市|巢湖市|滁州市‘, ‘hainan‘:‘三亞市|海口市|瓊海市|文昌市|東方市|昌江縣|陵水縣|樂東縣|保亭縣|五指山市|澄邁縣|萬寧市|儋州市|臨高縣|白沙縣|定安縣|瓊中縣|屯昌縣|海南‘, ‘jiangxi‘:‘南昌市|贛州市|上饒市|吉安市|九江市|新余市|撫州市|宜春市|景德鎮市|萍鄉市|鷹潭市|江西‘, ‘hubei‘:‘武漢市|宜昌市|襄樊市|荊州市|恩施州|黃岡市|孝感市|十堰市|鹹寧市|黃石市|仙桃市|天門市|隨州市|荊門市|潛江市|鄂州市|神農架林區|湖北‘, ‘shanxi2‘:‘太原市|大同市|運城市|長治市|晉城市|忻州市|臨汾市|呂梁市|晉中市|陽泉市|朔州市|山西‘, ‘liaoning‘:‘大連市|沈陽市|丹東市|遼陽市|葫蘆島市|錦州市|朝陽市|營口市|鞍山市|撫順市|阜新市|盤錦市|本溪市|鐵嶺市|遼寧‘, ‘taiwan‘:‘臺北市|高雄市|臺中市|新竹市|基隆市|臺南市|嘉義市|臺灣‘, ‘heilongjiang‘:‘齊齊哈爾市|哈爾濱市|大慶市|佳木斯市|雙鴨山市|牡丹江市|雞西市|黑河市|綏化市|鶴崗市|伊春市|大興安嶺地區|七臺河市|黑龍江‘, ‘neimenggu‘:‘赤峰市|包頭市|通遼市|呼和浩特市|鄂爾多斯市|烏海市|呼倫貝爾市|興安盟|巴彥淖爾盟|烏蘭察布盟|錫林郭勒盟|阿拉善盟|內蒙古‘, ‘guizhou‘:‘貴陽市|黔東南州|黔南州|遵義市|黔西南州|畢節地區|銅仁地區|安順市|六盤水市‘, ‘gansu‘:‘蘭州市|天水市|慶陽市|武威市|酒泉市|張掖市|隴南地區|白銀市|定西地區|平涼市|嘉峪關市|臨夏回族自治州|金昌市|甘南州|甘肅‘, ‘qinghai‘:‘西寧市|海西州|海東地區|海北州|果洛州|玉樹州|黃南藏族自治州|青海‘, ‘xinjiang‘:‘烏魯木齊市|伊犁州|昌吉州|石河子市|哈密地區|阿克蘇地區|巴音郭楞州|喀什地區|塔城地區|克拉瑪依市|和田地區|阿勒泰州|吐魯番地區|阿拉爾市|博爾塔拉州|五家渠市|克孜勒蘇州|圖木舒克市|新疆‘, ‘xizang‘:‘拉薩市|山南地區|林芝地區|日喀則地區|阿裏地區|昌都地區|那曲地區|西藏‘, ‘jiling‘:‘吉林市|長春市|白山市|延邊州|白城市|松原市|遼源市|通化市|四平市|吉林‘, ‘ningxia‘:‘銀川市|吳忠市|中衛市|石嘴山市|固原市|寧夏‘ } numdict = {} for key in citydict : sql = "select count(*) from model where location REGEXP ‘%s‘" % citydict[key] city = cur.execute(sql) num = int(cur.fetchmany(city)[0][0]) numdict[key] = num return render(request, ‘area.html‘,{‘jianxi‘:numdict[‘jianxi‘],‘beijin‘:numdict[‘beijin‘],‘guangdong‘:numdict[‘guangdong‘],‘shandong‘:numdict[‘shandong‘],‘jiangsu‘:numdict[‘jiangsu‘],‘henan‘:numdict[‘henan‘],‘shanghai‘:numdict[‘shanghai‘],‘hebei‘:numdict[‘hebei‘],‘zhejiang‘:numdict[‘zhejiang‘],‘shanxi‘:numdict[‘shanxi‘],‘hunan‘:numdict[‘hunan‘],‘chongqing‘:numdict[‘chongqing‘],‘fujian‘:numdict[‘fujian‘],‘tianjin‘:numdict[‘tianjin‘],‘yunnan‘:numdict[‘yunnan‘],‘sichuan‘:numdict[‘sichuan‘],‘guangxi‘:numdict[‘guangxi‘],‘anhui‘:numdict[‘anhui‘],‘hainan‘:numdict[‘hainan‘],‘jiangxi‘:numdict[‘jiangxi‘],‘hubei‘:numdict[‘hubei‘],‘shanxi2‘:numdict[‘shanxi2‘],‘liaoning‘:numdict[‘liaoning‘],‘taiwan‘:numdict[‘taiwan‘],‘heilongjiang‘:numdict[‘heilongjiang‘],‘neimenggu‘:numdict[‘neimenggu‘],‘guizhou‘:numdict[‘guizhou‘],‘gansu‘:numdict[‘gansu‘],‘qinghai‘:numdict[‘qinghai‘],‘xinjiang‘:numdict[‘xinjiang‘],‘xizang‘:numdict[‘xizang‘],‘jiling‘:numdict[‘jiling‘],‘ningxia‘:numdict[‘ningxia‘]})
{% load staticfiles %}
<!DOCTYPE html>
<html>
<head>    
    <meta charset="utf-8">    
    <title>Charts demo</title>  
    <script src="{% static "js/echarts.js" %}"></script>
    <script src="{% static "js/china.js" %}"></script>
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
  
</head>    
<body>    
  
    <div id="main" style="height:600px;"></div>   
    <script type="text/javascript">    
  
                var myChart = echarts.init(document.getElementById(‘main‘));  
                option = {
                    title : {
                        text: ‘淘寶模特所在省份分部情況‘,
                        subtext: ‘‘,
                        x:‘center‘
                    },
                    tooltip : {
                        trigger: ‘item‘
                    },
                    legend: {
                        orient: ‘vertical‘,
                        x:‘left‘,
                        data:[‘‘]
                    },
                    dataRange: {
                        min: 0,
                        max: 2500,
                        x: ‘left‘,
                        y: ‘bottom‘,
                        text:[‘高‘,‘低‘],           // 文本,默認為數值文本
                        calculable : true
                    },
                    toolbox: {
                        show: true,
                        orient : ‘vertical‘,
                        x: ‘right‘,
                        y: ‘center‘,
                        feature : {
                            mark : {show: true},
                            dataView : {show: true, readOnly: false},
                            restore : {show: true},
                            saveAsImage : {show: true}
                        }
                    },
                    roamController: {
                        show: true,
                        x: ‘right‘,
                        mapTypeControl: {
                            ‘china‘: true
                        }
                    },
                    series : [
                        {
                            name: ‘人數‘,
                            type: ‘map‘,
                            mapType: ‘china‘,
                            roam: false,
                            itemStyle:{
                                normal:{label:{show:true}},
                                emphasis:{label:{show:true}}
                            },
                            data:[
                                {name: ‘北京‘,value: {{ beijin }}},
                                {name: ‘江西‘,value: {{ jianxi }}},
                                {name: ‘廣東‘,value: {{ guangdong }}},
                                {name: ‘山東‘,value: {{ shandong }}},
                                {name: ‘江蘇‘,value: {{ jiangsu }}},
                                {name: ‘河南‘,value: {{ henan }}},
                                {name: ‘上海‘,value: {{ shanghai }}},
                                {name: ‘河北‘,value: {{ hebei }}},
                                {name: ‘浙江‘,value: {{ zhejiang }}},
                                {name: ‘陜西‘,value: {{ shanxi }}},
                                {name: ‘湖南‘,value: {{ hunan }}},
                                {name: ‘重慶‘,value: {{ chongqing }}},
                                {name: ‘福建‘,value: {{ fujian }}},
                                {name: ‘天津‘,value: {{ tianjin }}},
                                {name: ‘雲南‘,value: {{ yunnan }}},
                                {name: ‘四川‘,value: {{ sichuan }}},
                                {name: ‘廣西‘,value: {{ guangxi }}},
                                {name: ‘安徽‘,value: {{ anhui }}},
                                {name: ‘海南‘,value: {{ hainan }}},
                                {name: ‘江西‘,value: {{ jiangxi }}},
                                {name: ‘湖北‘,value: {{ hubei }}},
                                {name: ‘山西‘,value: {{ shanxi2 }}},
                                {name: ‘遼寧‘,value: {{ liaoning }}},
                                {name: ‘臺灣‘,value: {{ taiwan }}},
                                {name: ‘黑龍江‘,value: {{ heilongjiang }}},
                                {name: ‘貴州‘,value: {{ guizhou }}},
                                {name: ‘甘肅‘,value: {{ gansu }}},
                                {name: ‘青海‘,value: {{ qinghai }}},
                                {name: ‘新疆‘,value: {{ xinjiang }}},
                                {name: ‘西藏‘,value: {{ xizang }}},
                                {name: ‘吉林‘,value: {{ jiling }}},
                                {name: ‘寧夏‘,value: {{ ningxia }}},
                                {name: ‘內蒙古‘,value: {{ neimenggu }}},
                              
                            ]
                        }
                    ]
                };

                myChart.setOption(option);                     
  
          
    </script>    
  
</body>
</html>
{% load staticfiles %}
<!DOCTYPE html>
<head>
    <meta charset="utf-8">
    <title>動態數據展示</title>
</head>
<body>
    <!-- 為ECharts準備一個具備大小(寬高)的Dom -->
    <div id="main" style="height:400px"></div>
    <!-- ECharts單文件引入 -->
    <script src="http://echarts.baidu.com/build/dist/echarts.js"></script>
    <script type="text/javascript">
        // 路徑配置
        require.config({
            paths: {
                echarts: ‘http://echarts.baidu.com/build/dist‘
            }
        });
        
        // 使用
        require(
            [
                ‘echarts‘,
                ‘echarts/chart/bar‘ // 使用柱狀圖就加載bar模塊,按需加載
            ],
            function (ec) {
                // 基於準備好的dom,初始化echarts圖表
                var myChart = ec.init(document.getElementById(‘main‘)); 
                var option = {
                    tooltip: {
                        show: true
                    },
                    legend: {
		        color:‘#0000FF‘,
                        data:[‘模特年齡‘]
                    },
                    xAxis : [
                        {
                            type : ‘category‘,
			      data : {{ category }}
                        }
                    ],
                    yAxis : [
                        {
                            type : ‘value‘
                        }
                    ],
                    series : [
                        {
                            "name":"模特年齡",
                            "type":"bar",
                            "data":{{ agedata  }}
                        }
                    ]
                };
        
                // 為echarts對象加載數據 
                myChart.setOption(option); 
            }
        );
    </script>
</body>

網站首頁:

技術分享

技術分享

技術分享

提交的信息會寫入數據庫中:

技術分享

模特年齡正態分布情況:

技術分享

首先對信息進行分詞處理,然後排序,選取出現頻率最高的前100個詞。

技術分享

這個花了我很多時間,要解決echarts地圖只精確到省或者直轄市,而我爬取到的數據可能是具體的某一個地方市名,針對這個問題:我首先找了一下各省下面的市都有哪些,sql語句使用正則匹配想要獲取的信息。我創建了個字典存放省名和下屬的市名。另外創建個字典存放省名和匹配到的人數。

技術分享

簡單小結:這裏面涉及到的知識點還挺多的:

爬蟲:我使用的requests和beautiful這倆庫。

數據庫:使用的是mysql,涉及到數據庫編碼,sql查詢,模糊匹配,python對數據庫的操作,中文顯示亂碼的問題。

詞雲:jieba進行分詞,pytagcloud用來生成詞雲。

django:views、templates、static 、url,因為我用的MySQLdb,所以沒有使用django自身的ORM(models),這樣我覺得更靈活。

前端展示:bootstrap(主要用來做網站的布局)和echarts(進行圖表展示和數據分析用)。






本文出自 “付煒超” 博客,請務必保留此出處http://9399369.blog.51cto.com/9389369/1953469

python實現數據爬取-清洗-持久化存儲-數據平臺可視化