大二下学期第二次个人作业第一阶段
CVPR部分的论文已爬取完毕,现在要实现查询的功能,主要能根据题目,作者,来源,年份,关键词进行查询。
但是关键词,爬取的网站中并没有,要对爬取内容进行抽取形成关键词,目前并没有实现。
来源就是论文来自那个议会:CVPR,ICCV,EVCA。现在只爬取了第一个。
前端页面:
css:
body { background-color: azure; } .mainbox { background-color: white; width: 800px; left: 0; right: 0; margin: 0 auto; } .athorbox { position: fixed; left: 0; } input { width: 600px; height: 20px } select { height: 20px; width: 100px; } button { height: 30px; width: 100px; font-size: 20px; background-color: aqua; } .tablebox { background-color: white; width: 1000px; height: 600px; left: 0; right: 0; margin: 0 auto; } table { border-collapse: collapse; margin: 0 auto; text-align: center; } table td, table th { border: 1px solid #cad9ea; color: #666; height: 30px; } table thead tr th { background-color: #CCE8EB; width: 100px; } table tr:nth-child(odd) { background: #fff; } table tr:nth-child(even) { background: #F5FAFA; }
html:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <link rel="stylesheet" type="text/css" href="../static/css/paper.css" /> </head> <script src="../static/js/jquery.js"></script> <body> <div class="mainbox"> <div calss="mainfind" align="center"> 题    目<input tyep="text" > <br><br> 关键词 <input type="text" > <br><br> 作   者 <input type="text" ><br><br> 年   份 <select > <option value="2020">2020</option> <option value="2019">2019</option> <option value="2018">2018</option> <option value="ALL">ALL</option> </select> 会   议 <select > <option value="CVPR">CVPR</option> <option value="ICCV">ICCV</option> <option value="EVCA">EVCA</option> <option value="ALL">ALL</option> </select> <button >提交</button> </div> </div> <hr> <div class="tablebox"> <table> <thead> <tr> <th>题目</th> <th>作者</th> <th>来源</th> <th>年份</th> <th>关键词</th> <tr> </thead> <tbody> </tbody> </table> </div> </body> <script> var btn=document.getElementById("submit"); btn.onclick=function () { var title = document.getElementById("title").value; var author = document.getElementById("author").value; var mainworld = document.getElementById("mainworld").value; var year = $(".year").find("option:selected").text(); var meet = $(".meet").find("option:selected").text(); $.ajax({ url: "/query", data: { title: title, author: author, mainworld: mainworld, year: year, meet: meet }, success: function (data) { $(".tablebox tbody").empty(); for (var i = 0; i < data.data.length; i++) { var Day = data.data[i][0].split(' ') appendHtmlBody = "<tr><td>" + "<a href='"+data.data[i][4]+"' target='view_window'>"+data.data[i][0] + "</a></td><td>" + data.data[i][1] + "</td><td>" + data.data[i][2] + "</td><td>" + data.data[i][3] + "</td><td>" + data.data[i][5] + "</td></tr>" $(".tablebox tbody").append(appendHtmlBody); } }, error: function (xhr, type, errorThrown) { } }) } </script> </html>
后台部分:
import operator from flask import Flask, request, jsonify from flask import render_template import util app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello World!' @app.route("/query") def query_data(): title=request.values.get("title") mainworld=request.values.get("mainworld") author=request.values.get("author") year=request.values.get("year") meet=request.values.get("meet") Data=[] for data in util.query_data(title,mainworld,author,year,meet): Data.append(data) return jsonify({"data":Data}) @app.route('/tem2') def hello_world2(): return render_template("show.html") if __name__ == '__main__': app.run()
def query_data(title,mainworld,author,years,meet): if(meet=="ALL"): meet="" if(years=="ALL"): years="" sql = 'select title,authors,meet,yeardata,url,keyworld from paper_data ' 'where 1=1' if(title!=""): sql=sql+' and (title like '+"'"+"%"+title+"%"+"') " if(mainworld!=""): sql=sql+' and (keyworld like '+"'"+"%"+mainworld+"%"+"') " if(author!=""): sql=sql+' and (authors like '+"'"+"%"+author+"%"+"') " if(years!=""): sql=sql+' and (yeardata like '+"'"+"%"+years+"%"+"') " if(meet!=""): sql=sql+' and (meet like '+"'"+"%"+meet+"%"+"') " print(sql) res = query(sql) print(res) return res