ppt内容

作者: 千砚 | 来源:发表于2018-03-22 10:14 被阅读29次

    项目名称

    爱生活爱电影

    小组成员

    文静 魏麟苏 周世豪 左良玉

    学习进度

    第一周:python语言的学习
    输入输出、python的数据结构、控制结构、数据库的连接

    第二周:redis、flask、selenium、scrapy的学习

    第三周:人脸识别相关应用

    项目内容

    用python语言实现功能:
    通过爬虫程序爬取互联网上电影列表和电影简介,通过Web程序按电影名称或图片识别搜索电影列表、并能查看详情,需提供下载地址。还需要有登录、注册功能,可以使用账号密码或人脸识别认证,登录后可以对电影进行点赞和评论。用到mysql,redis、分词和爬虫技术。

    评论从豆瓣获取(公众号)

    额外任务:

    Try-catch 网络出错

    记录下载到的位置页面第几项

    模块划分

    爬虫 爬取网站的内容

    数据库 存取爬取的内容

    web 登录注册功能

    代码展示

    项目结构.jpg

    红色方框内是系统自动生成的框架(假装有)
    images文件夹中包含的是图片
    static文件夹里包含的是.css文件
    templates包含的是html文件

    爬虫模块使用了scrapy架构
    使用命令行语句新建项目,自动生成框架和.py文件
    在cmd中输入一下命令,新建项目爬虫以及开始爬虫
    新建一个项目,并进入项目目录。

    scrapy startproject myMovie
    cd myMovie
    
    scrapy genspider movie www.dytt8.net   #生成movie.py文件
    
    scrapy crawl movie
    

    编写movie.py文件

    import scrapy
    from myMovie.items import MymovieItem
    import time
    from gettitle1 import getName
    import sys
    sys.path.append('D:\python\myMovie\test.py')
    

    导入内容,其中用到了scrapy架构,从items.py文件导入了MymovieItem函数,time,以及在自己编写的文件夹外的getName.py文件内的gettitle1函数。

    css文件

    .index {
        margin-top: 60px;
    }
    .index .op  {
        width: 200px;
        margin-top: 20px;
        float: right;
    }
    .index .movies {
        margin-top: 60px;
    }
    

    html文件

    html文件.jpg

    其中
    login.html内容

    <html>
    <head>
      <link href="/static/style.css" rel="stylesheet">
      <title>登录页面</title>
    </head>
    <body>
      {% if message %}
      <p style="color:red">{{ message }}</p>
      {% endif %}
      <div class = "login" style = "width: 170px;margin: 0 auto;">
      <form action="/login" method="post">
        <legend>请登录:</legend>
        <p><input name="username" placeholder="Username" value="{{ username }}"></p>
        <p><input name="password" placeholder="Password" type="password"></p>
        <p><button type="submit" onclick="alert('登陆成功')">登录</button></p>
      </form>
      <form action="/register" method="get">
             <p><button type="submit">注册账号</button></p>
      </form>
        <form action="/getpassword" method="get">
              <p><button type = "submit">找回密码</button></p>
      </form>
      </div>
    </body>
    </html>
    

    如果验证失败,需重新输入,显示错误提示message,username也会写入

    {% if message %}
      <p style="color:red">{{ message }}</p>
    {% endif %}
    

    可以展示登录界面(待截屏)
    main.py

    from flask import Flask, render_template, request, redirect, session, url_for
    import pymysql
    
    db = pymysql.connect("localhost","root","123456","test", charset = 'utf8' )
    cursor = db.cursor()
    
    app = Flask(__name__)
    
    # 登录页面显示
    @app.route('/login', methods=['GET'])
    def home():
        session['logined'] = 0
        #  render_template() 方法来渲染模板。将模板名和作为关键字的参数传入模板的变量
        return render_template('login.html')
    
    
    # 输入用户名、密码后提交的处理页面,用于验证用户名和密码
    @app.route('/login', methods=['POST'])
    def logincheck():
        username = request.form['username']
        password = request.form['password']
        sql = "select * from users where username = '%s'" % username
        print(sql)
        cursor.execute(sql)
        user = cursor.fetchone()
        if user:
            if user[2] == password:
                session['logined'] = 1
                return redirect(url_for('movies'))
                #return redirect(url_for('news'))
        message = "用户名或密码错误"
        return render_template('login.html',message = message, username = username)
    
    @app.route('/register', methods=['get'])
    def register():
        return render_template('register.html')
    
    @app.route('/register', methods=['post'])
    def re():
        username = request.form['username']
        password = request.form['password']
        password1 = request.form['password1']
        question1 = request.form['question1']
        answer1 = request.form['answer1']
        question2 = request.form['question2']
        answer2 = request.form['answer2']
        print(username, password, password1,question1,answer1, question2, answer2)
        #检测用户名是否重复
        #sql = "select * from users"
        #cursor.execute(sql)
    
        if password and password == password1:
            sql = "insert into users(`username`, `password`, `question1`, `answer1`, `question2`, `answer2`) VALUES ('%s', '%s', '%s', '%s', '%s', '%s' )" % (username, password, question1, answer1, question2, answer2)
            print(sql)
            cursor.execute(sql)
            db.commit()
            return render_template('login.html', username=username)
        message = "两次输入的密码不一致"
    
        return render_template('register.html', message=message, username=username)
    
    # 找回密码
    @app.route('/getpassword', methods=['post'])
    def getpassword():
        return render_template('getpassword.html')
    
    # 主页:显示数据库中的内容
    @app.route('/index', methods=['GET'])
    def movies():
        if 'logined' in session and session['logined'] == 1: # 保证存在
            sql = "select * from movies"
            cursor.execute(sql)
            movies = cursor.fetchall()
            newList = []
            for item in movies:
                dnews = {}#列表还是???
                dnews['id'] = item[0]
                dnews['title'] = item[1]
                dnews['link'] = item[2]
                dnews['desc'] = item[3]
                dnews['download_url'] = item[4]
                newList.append(dnews)
            print(newList)
            return render_template('index.html',newList = newList)
        return "身份认证失败"
    
    app.secret_key =  ('SECRET_KEY')
    
    if __name__ == '__main__':
        app.run(debug = True)
    

    index.html

    <html>
    <head>
      <link href="/static/style.css" rel="stylesheet">
      <title>最新电影</title>
    </head>
    <body>
    <div class = "index">
      <div class = "op">
        <p>您好 ,{{username}}</p>
        <a href = "/news/exit">退出</a>
      </div>
        <div>
      <ul class = "movies">
        {% for item in newList%}
        <li>
          <div class = "title">电影名称:{{item.title}}
          </div>
          <a class = "link" href = {{item.link}}>点击查看详情</a>
          <div class = "desc">描述:{{item.desc}}</div>
          <a class = "download_url">迅雷下载链接:{{item.download_url}}</a>
      </li>
        {% endfor %}
      </ul>
            </div>
    </div>
    </body>
    </html>
    

    用动态做出(四个人分别讲的内容)最后写,PPT中留位置

    爬虫爬取内容到数据库
    数据库到web显示的流程
    登录注册的流程和代码之间的联系
    爬虫框架各个文件之间的联系

    相关文章

      网友评论

        本文标题:ppt内容

        本文链接:https://www.haomeiwen.com/subject/nnioqftx.html