Pythonは車のデータマイニングと分析を使用しました*

中古住宅のデータの取得

実験環境

実験環境
のWindows 10
のPython 3.8
PyCharm 2019
Scrapy 1.8.0



コンテンツ実験

データクロール:からの書き込み爬虫類中古車ホームグラブ中古車情報。:次のようにデータ・ページの分析がクロールされる
データは、車両名、価格、地域、テーブル大幅な燃費のタイムカード、排出量、トランスミッション、および価格の全額の他の寸法が含ま

データ分析:データ分析
1)車の価格の異なる部分のための好み




実験手順

データクロール

まず、確立scrapyプロジェクトused_cars

C:\Users\15650>cd desktop

C:\Users\15650\Desktop>scrapy startproject used_cars

プロジェクトを開き、Pycharmを使用して動作


第二に、定義データ(部分コード)items.pyにクロールする必要があります

import scrapy

class UsedCarItem(scrapy.Item):
    car_name = scrapy.Field() # 汽车名称
    car_price = scrapy.Field() # 汽车价格

items.py:データ構造定義ファイルを抽出する必要があります。

第三に、クモの設立の爬虫類PYファイル

import scrapy

from cars.items import CarsItem

class SpSpider(scrapy.Spider):
    name = "sp"
    allowed_domains = ['guazi.com']
    start_urls = [
        "https://www.guazi.com/linyi/7369b6907daba7c5x.htm#fr_page=index&fr_pos=rec&fr_no=0",
        "https://www.guazi.com/cq/0833698720dd1462x.htm#fr_page=index&fr_pos=zhunxin&fr_no=1"
        ]

    def parse(self,response):
        items = []
        sel = scrapy.selector.Selector(response)
        sites = sel.xpath('/html/body/div[4]/div[3]/div[2]')
        for site in sites:
            item = CarsItem()
            item['name'] = site.xpath('h2/text()').extract()
            item['brand'] = site.xpath('/html/body/div[4]/div[5]/div[2]/table[1]/tbody/tr[2]/td[2]').extract()
            item['registration_time'] = site.xpath('ul/li[1]/span/text()').extract()
            item['show_mileage'] = site.xpath('ul/li[2]/span/text()').extract()
            item['displacement'] = site.xpath('ul/li[3]/span/text()').extract()
            item['gearbox'] = site.xpath('ul/li[4]/span/text()').extract()
            item['full_price'] = site.xpath('/html/body/div[4]/div[3]/div[2]/div[1]/div[2]/span[1]/text()').extract()
            items.append(item)

        return items


第四に、爬虫類を実行し、JSONファイルに表示








第三に、データ収集







公開された46元の記事 ウォン称賛15 ビュー30000 +

おすすめ

転載: blog.csdn.net/qq_41850194/article/details/105099114