python爬虫、Django项目-电子词典

环境:

Ubuntu16.04 + python3.5.2 + Django1.11.8

功能点:

1、将 "常用单词.txt" 的翻译存入数据库中

2、实现用户的注册、登录验证

3、查询单词

    1、若数据库中存在,则返回数据库中的信息

    2、若数据库中不存在,则爬取有道中的翻译并返回,同时提示是否保存到本地

        1、是:保存到本地数据库

        2、否:返回到查询页继续查询

步骤:

1、百度到满足要求的 “常用单词.txt”,将其中的数据根据正则匹配进行分隔,写入mysql数据库中

2、利用Django构建服务器框架

3、编写爬虫模块,并导入Django框架中使用

Django文档结构

├── dictionary
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── __pycache__
│   │   ├── __init__.cpython-35.pyc
│   │   ├── settings.cpython-35.pyc
│   │   ├── urls.cpython-35.pyc
│   │   └── wsgi.cpython-35.pyc
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── index
│   ├── admin.py
│   ├── apps.py
│   ├── __init__.py
│   ├── migrations
│   │   ├── 0001_initial.py
│   │   ├── 0002_users_is_active.py
│   │   ├── 0003_auto_20180424_1526.py
│   │   ├── __init__.py
│   │   └── __pycache__
│   │       ├── 0001_initial.cpython-35.pyc
│   │       ├── 0002_users_is_active.cpython-35.pyc
│   │       ├── 0003_auto_20180424_1526.cpython-35.pyc
│   │       └── __init__.cpython-35.pyc
│   ├── models.py
│   ├── __pycache__
│   │   ├── admin.cpython-35.pyc
│   │   ├── __init__.cpython-35.pyc
│   │   ├── models.cpython-35.pyc
│   │   ├── urls.cpython-35.pyc
│   │   ├── views.cpython-35.pyc
│   │   └── youdao.cpython-35.pyc
│   ├── static
│   ├── templates
│   │   ├── after_insert.html
│   │   ├── index.html
│   │   ├── login.html
│   │   ├── main2.html
│   │   ├── main.html
│   │   └── register.html
│   ├── tests.py
│   ├── urls.py
│   ├── views.py
│   └── youdao.py

├── manage.py

代码部分

dictionary/urls.py

from django.conf.urls import url, include
from django.contrib import admin

urlpatterns = [
    url(r'^admin/', admin.site.urls),
]

urlpatterns += [
    url(r'^', include('index.urls')),
]

dictionary/settings

"""
Django settings for dictionary project.

Generated by 'django-admin startproject' using Django 1.11.8.

For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'fccc1xu2tqde@(wzdn8=)5btxu3xi8lyrx=_f=gg_0jz8+6@m#'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['*']

# Application definition

INSTALLED_APPS = [
    'django.contrib
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值