Developed and implemented second-hand car data crawling and analysis based on Python+Flask framework

Author's homepage: Programming Paper Cranes

About the author: Java, front-end, and Python have been developed for many years, and have worked as engineers, project managers, and architects.

Main content: Java project development, Python project development, university data and AI project development, microcontroller project design, interview technology compilation, latest technology sharing

Collect, like and don’t get lost. It’s good to follow the author.

Get the source code at the end of the article

Item Number: BS-Python-011

1. Environmental introduction

Language environment: Python3.8

Development tools: PyCharm

Development technology: Flask+Echart, etc.

2. Project introduction

This project is developed and implemented based on Python3.8. The system consists of two parts. One part is the data crawler part, which mainly captures the used car information data disclosed by the Guazi second-hand car website platform and stores it in a csv file. Part of the process is data analysis and display. The data in the csv file is read through the program and displayed on the HTML web page, and the data is displayed visually through the graphical report tool. The program implements the WEB development part based on the Flask development framework. After running, directly enter http://localhost:5000 in the browser to view the data analysis results.

Three, system display

System homepage

Analysis and display of vehicle information list

Used car data analysis column chart in each city

Statistical chart of vehicle registration time

Used car price comparison chart

Fourth, the core code display

from flask import Flask, render_template
import csv

app = Flask(__name__)
# 指定文件名,然后使用 with open() as 打开

@app.route('/')
def home():
    return render_template("index.html")

@app.route('/index')
def index():
    return render_template("index.html")

@app.route('/cars')
def cars():
    dataList = []
    filename = 'data.csv'
    with open(filename, 'r', encoding='utf-8') as f:
        # 创建阅读器(调用csv.reader()将前面存储的文件对象最为实参传给它)
        reader = csv.reader(f)
        # 调用了next()一次,所以这边只调用了文件的第一行,并将头文件存储在header_row中
        header_row = next(reader)
        for row in reader:
            dataList.append(row)
    return render_template("cars.html", cars=dataList)

@app.route('/city')
def city():
    return render_template("city.html")

@app.route('/year')
def year():
    return render_template("year.html")

@app.route('/carsDetail')
def carsDetal():
    return render_template("carsDetail.html")

if __name__ == '__main__':
    app.run()
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0" name="viewport">

  <title>二手车数据分析平台</title>
  <meta content="" name="descriptison">
  <meta content="" name="keywords">

  <!-- Favicons -->
  <link href="static/assets/img/favicon.png" rel="icon">
  <link href="static/assets/img/apple-touch-icon.png" rel="apple-touch-icon">

  <!-- Google Fonts -->
  <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Raleway:300,300i,400,400i,600,600i,700,700i,900" rel="stylesheet">

  <!-- Vendor CSS Files -->
  <link href="static/assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
  <link href="static/assets/vendor/icofont/icofont.min.css" rel="stylesheet">
  <link href="static/assets/vendor/boxicons/css/boxicons.min.css" rel="stylesheet">
  <link href="static/assets/vendor/animate.css/animate.min.css" rel="stylesheet">
  <link href="static/assets/vendor/venobox/venobox.css" rel="stylesheet">
  <link href="static/assets/vendor/aos/aos.css" rel="stylesheet">

  <!-- Template Main CSS File -->
  <link href="static/assets/css/style.css" rel="stylesheet">
</head>

<body>
  <!-- ======= Header ======= -->
  <header id="header">
    <div class="container">

      <div class="logo float-left">
        <h1 class="text-light"><a href="temp.html"><span></span></a></h1>
        <!-- Uncomment below if you prefer to use an image logo -->
        <!-- <a href="temp.html"><img src="static/assets/img/logo.png" alt="" class="img-fluid"></a>-->
      </div>

      <nav class="nav-menu float-right d-none d-lg-block">
        <ul>
          <li class="active"><a href="/index">首页</a></li>
          <li><a href="/cars">车辆信息</a></li>
          <li><a href="/city">城市分布</a></li>
          <li><a href="/year">车辆上牌时间</a></li>
          <li><a href="/carsDetail">价格对比</a></li>
        </ul>
      </nav><!-- .nav-menu -->

    </div>
  </header><!-- End Header -->

  <!-- ======= Our Team Section ======= -->
    <section id="team" class="team">
      <div class="container">

        <div class="section-title">
          <h2>二手车数据分析平台</h2>
          <p></p>
        </div>

        <!-- ======= Counts Section ======= -->
    <section class="counts section-bg">
      <div class="container">

        <div class="row">

          <div class="col-lg-3 col-md-6 text-center" data-aos="fade-up">
              <a href="/cars">
            <div class="count-box">
              <i class="icofont-document-folder" style="color: #20b38e;"></i>
              <span data-toggle="counter-up">13626</span>
              <p>车辆信息</p>
            </div>
              </a>
          </div>

          <div class="col-lg-3 col-md-6 text-center" data-aos="fade-up" data-aos-delay="200">
              <a href="/city">
            <div class="count-box">
              <i class="icofont-document-folder" style="color: #20b38e;"></i>
              <span data-toggle="counter-up">8</span>
              <p>目标城市分布</p>
            </div>
              </a>
          </div>

          <div class="col-lg-3 col-md-6 text-center" data-aos="fade-up" data-aos-delay="400">
              <a href="/year">
            <div class="count-box">
              <i class="icofont-document-folder" style="color: #20b38e;"></i>
              <span data-toggle="counter-up">10</span>
              <p>上牌时间</p>
            </div>
              </a>
          </div>

          <div class="col-lg-3 col-md-6 text-center" data-aos="fade-up" data-aos-delay="600">
              <a href="/carsDetail">
            <div class="count-box">
              <i class="icofont-document-folder" style="color: #20b38e;"></i>
              <span data-toggle="counter-up">2</span>
              <p>价格对比</p>
            </div>
              </a>
          </div>

        </div>

      </div>
    </section><!-- End Counts Section -->

      </div>
    </section><!-- End Our Team Section -->


  <a href="#" class="back-to-top"><i class="icofont-simple-up"></i></a>

  <!-- Vendor JS Files -->
  <script src="static/assets/vendor/jquery/jquery.min.js"></script>
  <script src="static/assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
  <script src="static/assets/vendor/jquery.easing/jquery.easing.min.js"></script>
  <script src="static/assets/vendor/php-email-form/validate.js"></script>
  <script src="static/assets/vendor/jquery-sticky/jquery.sticky.js"></script>
  <script src="static/assets/vendor/venobox/venobox.min.js"></script>
  <script src="static/assets/vendor/waypoints/jquery.waypoints.min.js"></script>
  <script src="static/assets/vendor/counterup/counterup.min.js"></script>
  <script src="static/assets/vendor/isotope-layout/isotope.pkgd.min.js"></script>
  <script src="static/assets/vendor/aos/aos.js"></script>

  <!-- Template Main JS File -->
  <script src="static/assets/js/main.js"></script>

</body>

</html>

4. Project summary

This project has a clear structure and complete functions, and can be used for graduation projects or course design.

Guess you like

Origin blog.csdn.net/BS009/article/details/132664773