Python rental data analysis crawler national rental data

Technology stack: python language bootstrap framework jquery css javascript html

Crawling website: Shell rent a house (can crawl data of cities across the country)

Function:

Rental information data display, number distribution of rental addresses,

Rental house type statistics, rental house price statistical analysis,

Rental area analysis, housing orientation analysis,

Statistical analysis of the average price of housing units, statistical analysis of housing floors,

Statistical analysis of housing floors and prices, statistical analysis of housing addresses and prices,

Housing related information word cloud display

The core of the Django framework includes: an object-relational mapper, used as a medium between the data model (defined in the form of Python classes) and the relational database; a URL dispatcher based on regular expressions; a view system, used to process requests ; and a templating system [5].

Also included in the core framework are:

A lightweight, standalone web server for development and testing.

A form serialization and validation system for converting between HTML forms and data suitable for database storage.

A caching framework with several options for caching.

Middleware support, allowing intervention in various stages of request processing.

The built-in distribution system allows components in the application to communicate with each other using predefined signals.

A serialization system capable of generating or reading Django model instances expressed in XML or JSON.

A system for extending the capabilities of template engines.

Django, pronounced like (sticky). It is an open source web development framework written in python language and follows the MVC design pattern. The main purpose of Django is to develop database-driven websites easily and quickly. It emphasizes code reuse, and multiple components can easily serve the entire framework in the form of "plug-ins". Django has many powerful third-party plug-ins, and can also develop its own toolkit. It makes Django highly scalable, and it also emphasizes rapid development and DRY principles.

Django is a heavyweight open source Web framework based on P)rthon. Django has a highly customized ORM and a lot of APL simple

Flexible view writing, elegant URL, templates suitable for rapid development and powerful management background, which make it an excellent choice for Python Web development

The field has an unshakable position. Famous websites such as Facebook, Facebook, eFox, and National Geographic all use D1go for development.

有3 种方式,分别是使用pip 安装Django 、使用virtualenv 安装Django 和使用Anaconda 安装Django, 本文使用pip命令安装。

创建Django 项目

(1) 首先在D 盘(读者可以根据实际情况选择)根目录下创建用千保存项目文件的目录, 这里创建的目录为“D:\Webproj ects”。

( 2) 在Webprojects 文件夹中创建environments 目录用千放置虚拟环境, 然后打开cmd, 输入如下创建环境命令:

: virtualenv D:\Webprojects\envi ronments\django2.0

(3) 使用如下命令在命令行激活环境:

: D: \Webprojects\environments\dj ango2. 0\Scripts\activate

( 4) 使用“ django-admin " 命令创建一个项目:

django-admin startproject demo

( 5 ) 使用压,cham1 打开demo 项目, 查看目录结构,

说明:Dj ango 项目中的文件及说明

manage.py Dj ango 程序执行的入口

db.sqlite3 SQLite 的数据库文件, Dj ango 默认使用这种小型数据库存取数据,非必须

templates Dj ango 生成的HTML 模板文件夹,我们也可以在每个app 中使用模板文件夹

demo Dj ango 生成的和项目同名的配置文件夹

settings. py Dj ango 总的配置文件,可以配置App 、数据库、中间件、模板等诸多选项

urls .py Dj ango 默认的路由配置文件

wsg1.py Dj ango 实现的WSGI 接口的文件, 用来处理Web 请求

启动django

在pychann 中单击运行项目, 或者在虚拟环境命令行中执行以下命令运行项目:

python manage.py runserver

创建APP

在Dj ango 项目中,推荐使用App 来完成不同模块的任务, 通过执行如下命令可以启用一个应用

程序。

python manage. py startapp

此时,在项目的根目录下可以看到一个名称为的目录

数据模型( models.py)

(1) 在App 中添加数据模型 详情见models.py 中的代码 ,说明如下:

执行数据库迁移

创建完数据模型后, 开始做数据库迁移,用Djai1go 默认自带的SQLite 数据库。在项目的settings.py 配置文件中找到如下的配置:

python manage . py makemigrations # 生成迁移文件

python manage . py migrate # 迁移数据库, 创建新表

路由(urls.py)-----详细见urls.py代码文件

URL路由流程:

(1)Django 查找全局urlpattems 变量(urls.py) 。

(2)按照先后顺序,对URL 逐一匹配urlpattems 每个元素。

(3)找到第一个匹配时停止查找, 根据匹配结果执行对应的处理函数。

(4)如果没有找到匹配或出现异常, Django 进行错误处理。

Django 模板

django 指定的模板引擎在settings.py 文件中定义:

TEMPLATES = [{

# 模板引擎,默认为Django模板

0BACKEND0: 'django. template. backends. django. DjangoTemplates' ,

,DIRS' : [] J # 模板所在的目录

'APP DIRS' : True, #是否启用AP P 目录

OPTIONS' : {

},

},

MySQL是一个开源的关系型数据库管理系统,由瑞典MySQL AB公司1995年开发,迅速成为最流行的开源关系型数据库管理系统。在 WEB 应用方面 MySQL 是最好的 RDBMS(Relational Database Management System:关系数据库管理系统)应用软件之一。2008被Sun公司10亿美金收购,2009年Sun被Oracle收购。MariaDB应运而生。(MySQL的创造者担心MysQL有闭源的风险,因此创建了MySQL的分支项目MariaDB)MySQL6.x版本之后分为社区版和商业版(付费,功能更强大)。MySQL是一种关联数据库管理系统,将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性。MySQL是可以定制的,采用了GPL(GNU General Public License)协议,你可以修改源码来开发自己的MySQL系统。MySQL支持大型的数据库,可以处理拥有上千万条记录的大型数据库。支持5000万条记录的数据仓库,32位系统表文件最大可支持4GB,64位系统支持最大的表文件为8TB。MySQL使用标准的SQL数据语言形式。MySQL 可以运行于多个系统上,并且支持多种语言。这些编程语言包括 C、C++、Python、Java、Perl、PHP、Eiffel、Ruby 。

Guess you like

Origin blog.csdn.net/2201_75772776/article/details/129229137