av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

Python爬取房產(chǎn)數(shù)據(jù),在地圖上展現(xiàn)!

小伙伴,我又來了,這次我們寫的是用python爬蟲爬取烏魯木齊的房產(chǎn)數(shù)據(jù)并展示在地圖上,地圖工具我用的是 BDP個人版-免費(fèi)在線數(shù)據(jù)分析軟件,數(shù)據(jù)可視化軟件 ,這個可以導(dǎo)入csv或者excel數(shù)據(jù)。

創(chuàng)新互聯(lián)公司是專業(yè)的松原網(wǎng)站建設(shè)公司,松原接單;提供成都網(wǎng)站設(shè)計、成都網(wǎng)站制作、外貿(mào)網(wǎng)站建設(shè),網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行松原網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊,希望更多企業(yè)前來合作!

  • 首先還是分析思路,爬取網(wǎng)站數(shù)據(jù),獲取小區(qū)名稱,地址,價格,經(jīng)緯度,保存在excel里。再把excel數(shù)據(jù)上傳到BDP網(wǎng)站,生成地圖報表

本次我使用的是scrapy框架,可能有點大材小用了,主要是剛學(xué)完用這個練練手,再寫代碼前我還是建議大家先分析網(wǎng)站,分析好數(shù)據(jù),再去動手寫代碼,因為好的分析可以事半功倍,烏魯木齊樓盤,2017烏魯木齊新樓盤,烏魯木齊樓盤信息 - 烏魯木齊吉屋網(wǎng) 這個網(wǎng)站的數(shù)據(jù)比較全,每一頁獲取房產(chǎn)的LIST信息,并且翻頁,點進(jìn)去是詳情頁,獲取房產(chǎn)的詳細(xì)信息(包含名稱,地址,房價,經(jīng)緯度),再用pipelines保存item到excel里,最后在bdp生成地圖報表,廢話不多說上代碼:

JiwuspiderSpider.py

 
 
 
 
  1. # -*- coding: utf-8 -*- 
  2. from scrapy import Spider,Request 
  3. import re 
  4. from jiwu.items import JiwuItem 
  5.  
  6.  
  7. class JiwuspiderSpider(Spider): 
  8.     name = "jiwuspider" 
  9.     allowed_domains = ["wlmq.jiwu.com"] 
  10.     start_urls = ['http://wlmq.jiwu.com/loupan'] 
  11.  
  12.     def parse(self, response): 
  13.         """ 
  14.         解析每一頁房屋的list 
  15.         :param response:  
  16.         :return:  
  17.         """ 
  18.         for url in response.xpath('//a[@class="index_scale"]/@href').extract(): 
  19.             yield Request(url,self.parse_html)  # 取list集合中的url  調(diào)用詳情解析方法 
  20.  
  21.         # 如果下一頁屬性還存在,則把下一頁的url獲取出來 
  22.         nextpage = response.xpath('//a[@class="tg-rownum-next index-icon"]/@href').extract_first() 
  23.         #判斷是否為空 
  24.         if nextpage: 
  25.             yield Request(nextpage,self.parse)  #回調(diào)自己繼續(xù)解析 
  26.  
  27.  
  28.  
  29.     def parse_html(self,response): 
  30.         """ 
  31.         解析每一個房產(chǎn)信息的詳情頁面,生成item 
  32.         :param response:  
  33.         :return:  
  34.         """ 
  35.         pattern = re.compile('.*?lng = \'(.*?)\';.*?lat = \'(.*?)\';.*?bname = \'(.*?)\';.*?' 
  36.                              'address = \'(.*?)\';.*?price = \'(.*?)\';',re.S) 
  37.         item = JiwuItem() 
  38.         results = re.findall(pattern,response.text) 
  39.         for result in results: 
  40.             item['name'] = result[2] 
  41.             item['address'] = result[3] 
  42.             # 對價格判斷只取數(shù)字,如果為空就設(shè)置為0 
  43.             pricestr =result[4] 
  44.             pattern2 = re.compile('(\d+)') 
  45.             s = re.findall(pattern2,pricestr) 
  46.             if len(s) == 0: 
  47.                 item['price'] = 0 
  48.             else:item['price'] = s[0] 
  49.             item['lng'] = result[0] 
  50.             item['lat'] = result[1] 
  51.         yield item 

item.py

 
 
 
 
  1. # -*- coding: utf-8 -*- 
  2.  
  3. # Define here the models for your scraped items 
  4. # See documentation in: 
  5. # http://doc.scrapy.org/en/latest/topics/items.html 
  6.  
  7. import scrapy 
  8.  
  9.  
  10. class JiwuItem(scrapy.Item): 
  11.     # define the fields for your item here like: 
  12.     name = scrapy.Field() 
  13.     price =scrapy.Field() 
  14.     address =scrapy.Field() 
  15.     lng = scrapy.Field() 
  16.     lat = scrapy.Field() 
  17.  
  18.     pass 

pipelines.py 注意此處是吧mongodb的保存方法注釋了,可以自選選擇保存方式

 
 
 
 
  1. # -*- coding: utf-8 -*- 
  2.  
  3. # Define your item pipelines here 
  4. # Don't forget to add your pipeline to the ITEM_PIPELINES setting 
  5. # See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html 
  6. import pymongo 
  7. from scrapy.conf import settings 
  8. from openpyxl import workbook 
  9.  
  10. class JiwuPipeline(object): 
  11.     wb = workbook.Workbook() 
  12.     ws = wb.active 
  13.     ws.append(['小區(qū)名稱', '地址', '價格', '經(jīng)度', '緯度']) 
  14.     def __init__(self): 
  15.         # 獲取數(shù)據(jù)庫連接信息 
  16.         host = settings['MONGODB_URL'] 
  17.         port = settings['MONGODB_PORT'] 
  18.         dbname = settings['MONGODB_DBNAME'] 
  19.         client = pymongo.MongoClient(host=host, port=port) 
  20.  
  21.         # 定義數(shù)據(jù)庫 
  22.         db = client[dbname] 
  23.         self.table = db[settings['MONGODB_TABLE']] 
  24.  
  25.     def process_item(self, item, spider): 
  26.         jiwu = dict(item) 
  27.         #self.table.insert(jiwu) 
  28.         line = [item['name'], item['address'], str(item['price']), item['lng'], item['lat']] 
  29.         self.ws.append(line) 
  30.         self.wb.save('jiwu.xlsx') 
  31.  
  32.         return item 

最后報表的數(shù)據(jù)

mongodb數(shù)據(jù)庫

地圖報表效果圖:https://me.bdp.cn/share/index.html?shareId=sdo_b697418ff7dc4f928bb25e3ac1d52348


文章標(biāo)題:Python爬取房產(chǎn)數(shù)據(jù),在地圖上展現(xiàn)!
瀏覽路徑:http://uogjgqi.cn/article/cdjosee.html
掃二維碼與項目經(jīng)理溝通

我們在微信上24小時期待你的聲音

解答本文疑問/技術(shù)咨詢/運(yùn)營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流