Compare commits
55 Commits
Binary file not shown.
Binary file not shown.
@ -0,0 +1,173 @@
|
|||||||
|
from flask import *
|
||||||
|
from flask import Flask
|
||||||
|
from spider import *
|
||||||
|
from word import makeWordcloud
|
||||||
|
from pypinyin import lazy_pinyin,load_single_dict
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
datalist = []
|
||||||
|
movieScore = []
|
||||||
|
num = []
|
||||||
|
page=[1,2,3,4,5,6,7,8,9,10]
|
||||||
|
@app.route('/')
|
||||||
|
def index():
|
||||||
|
return render_template('first.html')
|
||||||
|
|
||||||
|
@app.route('/first')
|
||||||
|
def first():
|
||||||
|
return index()
|
||||||
|
|
||||||
|
@app.route('/movie')
|
||||||
|
def movie():
|
||||||
|
if len(datalist) == 0:
|
||||||
|
baseurl = "https://movie.douban.com/top250?start=" # 指定的网页超链接
|
||||||
|
datalist1 = getData1(baseurl) # 返回一个装有所有数据的列表
|
||||||
|
|
||||||
|
print(datalist1)
|
||||||
|
for item in datalist1:
|
||||||
|
datalist.append(item)
|
||||||
|
saveData1(datalist1, "top250.xls")
|
||||||
|
|
||||||
|
page=1
|
||||||
|
movies=[]
|
||||||
|
#对列表进行分割
|
||||||
|
for i in range(25):
|
||||||
|
movies.append(datalist[i])
|
||||||
|
return render_template('movie.html', movies=movies, page=page)
|
||||||
|
|
||||||
|
#进行分页
|
||||||
|
@app.route('/movie/start=<int:page>')
|
||||||
|
def movie2(page):
|
||||||
|
movies=[]
|
||||||
|
#对列表进行分割
|
||||||
|
if page: #page存在
|
||||||
|
first=(page-1)*25 #首页
|
||||||
|
last=page*25 #尾页
|
||||||
|
else :
|
||||||
|
first=0 #首页
|
||||||
|
last=25 #尾页
|
||||||
|
for i in range(first,last):
|
||||||
|
movies.append(datalist[i])
|
||||||
|
#列表分割完成
|
||||||
|
if page == 1:
|
||||||
|
return render_template('movie.html', movies=movies, page=page)
|
||||||
|
elif page == 2:
|
||||||
|
return render_template('movie.html', movies=movies, page=page)
|
||||||
|
elif page == 3:
|
||||||
|
return render_template('movie.html', movies=movies, page=page)
|
||||||
|
elif page == 4:
|
||||||
|
return render_template('movie.html', movies=movies, page=page)
|
||||||
|
elif page == 5:
|
||||||
|
return render_template('movie.html', movies=movies, page=page)
|
||||||
|
elif page == 6:
|
||||||
|
return render_template('movie.html', movies=movies, page=page)
|
||||||
|
elif page == 7:
|
||||||
|
return render_template('movie.html', movies=movies, page=page)
|
||||||
|
elif page == 8:
|
||||||
|
return render_template('movie.html', movies=movies, page=page)
|
||||||
|
elif page == 9:
|
||||||
|
return render_template('movie.html', movies=movies, page=page)
|
||||||
|
elif page == 10:
|
||||||
|
return render_template('movie.html', movies=movies, page=page)
|
||||||
|
else :
|
||||||
|
return render_template('movie.html', movies=movies, page=page)
|
||||||
|
|
||||||
|
@app.route('/score')
|
||||||
|
def score():
|
||||||
|
if (movieScore == [] or num == []):
|
||||||
|
# print("关于评分数据库被启动了!")
|
||||||
|
con = sqlite3.connect('data.db')
|
||||||
|
cur = con.cursor()
|
||||||
|
sql = "select score,count(score) from movie250 group by score"
|
||||||
|
data = cur.execute(sql)
|
||||||
|
for item in data:
|
||||||
|
movieScore.append(item[0])
|
||||||
|
num.append(item[1])
|
||||||
|
cur.close()
|
||||||
|
con.close()
|
||||||
|
return render_template('score.html', movieScore=movieScore, num=num)
|
||||||
|
|
||||||
|
@app.route('/word')
|
||||||
|
def word():
|
||||||
|
return render_template('word.html')
|
||||||
|
|
||||||
|
# 上传文件
|
||||||
|
@app.route('/upload_file', methods=['POST', 'GET'])
|
||||||
|
def upload():
|
||||||
|
if request.method == 'POST':
|
||||||
|
f = request.files['file']
|
||||||
|
f.filename = 'upload.jpg'
|
||||||
|
f.save(f.filename)
|
||||||
|
return render_template('word.html')
|
||||||
|
|
||||||
|
@app.route('/separate')
|
||||||
|
def separate():
|
||||||
|
return render_template('separate.html')
|
||||||
|
|
||||||
|
@app.route('/team')
|
||||||
|
def team():
|
||||||
|
return render_template('team.html')
|
||||||
|
|
||||||
|
@app.route('/cities')
|
||||||
|
def cities():
|
||||||
|
return render_template('cities.html')
|
||||||
|
|
||||||
|
@app.route('/citylist')
|
||||||
|
def citylist():
|
||||||
|
load_single_dict({ord('重'): 'chong'})
|
||||||
|
datalist1 = []
|
||||||
|
cityname = request.url
|
||||||
|
print("cityname=" + cityname)
|
||||||
|
cityname = "".join(lazy_pinyin(cityname))
|
||||||
|
cityname = cityname[cityname.index('=') + 1:len(cityname)]
|
||||||
|
print("cityname=" + cityname)
|
||||||
|
|
||||||
|
baseurl = "https://movie.douban.com/cinema/nowplaying/" + cityname + '/'
|
||||||
|
dbpath = "data.db"
|
||||||
|
|
||||||
|
con = sqlite3.connect(dbpath)
|
||||||
|
cur = con.cursor()
|
||||||
|
datalist_get = getData2(baseurl)
|
||||||
|
saveData2DB2(datalist_get, dbpath)
|
||||||
|
saveData2(datalist_get,"citylist.xls")
|
||||||
|
sql = "select * from citymovies"
|
||||||
|
data = cur.execute(sql)
|
||||||
|
|
||||||
|
for item in data:
|
||||||
|
datalist1.append(item)
|
||||||
|
cur.close()
|
||||||
|
con.close()
|
||||||
|
|
||||||
|
citymovies=[]
|
||||||
|
#对列表进行分割
|
||||||
|
for i in range(len(datalist1)):
|
||||||
|
citymovies.append(datalist1[i])
|
||||||
|
return render_template('citylist.html', citymovies = citymovies)
|
||||||
|
|
||||||
|
@app.route('/citylist.xls')
|
||||||
|
def citylist_xls():
|
||||||
|
return send_from_directory("./","citylist.xls")
|
||||||
|
|
||||||
|
@app.route('/top250.xls')
|
||||||
|
def top250_xls():
|
||||||
|
return send_from_directory("./","top250.xls")
|
||||||
|
|
||||||
|
@app.route('/upload.jpg')
|
||||||
|
def upldIMG():
|
||||||
|
return send_from_directory("./","upload.jpg")
|
||||||
|
|
||||||
|
@app.route('/output.jpg')
|
||||||
|
def outJPG():
|
||||||
|
makeWordcloud("upload.jpg")
|
||||||
|
return send_from_directory("./","output.jpg")
|
||||||
|
|
||||||
|
@app.route('/updateDBTb1')
|
||||||
|
def updateDBTb1():
|
||||||
|
datalist_get = getData1("https://movie.douban.com/top250?start=")
|
||||||
|
saveData1DB1(datalist_get, "data.db")
|
||||||
|
return "数据库更新成功!"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app.run(debug=True)
|
@ -1,151 +0,0 @@
|
|||||||
.topnav {
|
|
||||||
overflow: hidden;
|
|
||||||
background-color: whitesmoke;
|
|
||||||
float: left;
|
|
||||||
width: 100%;
|
|
||||||
text-align: center;
|
|
||||||
font-size: 20px;
|
|
||||||
position: fixed;
|
|
||||||
top:0;
|
|
||||||
box-shadow: 10px 5px 15px dimgray;
|
|
||||||
z-index: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.topnav a{
|
|
||||||
display: inline-block;
|
|
||||||
color: black;
|
|
||||||
text-align: center;
|
|
||||||
padding: 20px 60px;
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.topnav a:hover{
|
|
||||||
background-color: black;
|
|
||||||
}
|
|
||||||
|
|
||||||
.topnav a:active{
|
|
||||||
background-color: dimgray;
|
|
||||||
}
|
|
||||||
|
|
||||||
.header{
|
|
||||||
background: #7ec6bc; /* fallback for old browsers */
|
|
||||||
background: -webkit-linear-gradient(to right, #ebe717, #7ec6bc); /* Chrome 10-25, Safari 5.1-6 */
|
|
||||||
background: linear-gradient(to right, #ebe717, #7ec6bc); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
|
|
||||||
width: 100%;
|
|
||||||
color: white;
|
|
||||||
padding: 50px 0px;
|
|
||||||
text-align: center;
|
|
||||||
font-size: 72px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.topnav a:hover{
|
|
||||||
background-color: black;
|
|
||||||
color: white;
|
|
||||||
top:60px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#frame{
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
#frame iframe{
|
|
||||||
width: 100%;
|
|
||||||
height: 1800px;
|
|
||||||
border: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.introduction{
|
|
||||||
text-align: center;
|
|
||||||
width: 100%;
|
|
||||||
height: 500px;
|
|
||||||
padding-top: 80px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.try{
|
|
||||||
color: white;
|
|
||||||
text-decoration-line: none;
|
|
||||||
position: relative;
|
|
||||||
top:50px;
|
|
||||||
border: none;
|
|
||||||
font-size: 20px;
|
|
||||||
background-color: black;
|
|
||||||
padding: 30px 60px;
|
|
||||||
border-radius: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.try:hover{
|
|
||||||
background-color: dimgray;
|
|
||||||
}
|
|
||||||
|
|
||||||
.title{
|
|
||||||
font-size: 72px;
|
|
||||||
position: relative;
|
|
||||||
top:-80px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.playing{
|
|
||||||
width: 100%;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.lable{
|
|
||||||
position: relative;
|
|
||||||
top:100px;
|
|
||||||
font-size: 48px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.searching{
|
|
||||||
width: 100%;
|
|
||||||
height: 50px;
|
|
||||||
position: relative;
|
|
||||||
top:100px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.searching ul{
|
|
||||||
list-style-type: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.searching ul li{
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
|
|
||||||
.searching input{
|
|
||||||
width: 800px;
|
|
||||||
height: 80px;
|
|
||||||
font-size: 48px;
|
|
||||||
border-radius: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.searching input:focus{
|
|
||||||
background-color: black;
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.searching_logo button{
|
|
||||||
text-align: center;
|
|
||||||
border: none;
|
|
||||||
width: 88px;
|
|
||||||
height: 88px;
|
|
||||||
font-size: 48px;
|
|
||||||
position: relative;
|
|
||||||
top: 4px;
|
|
||||||
border-radius: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.searching_logo button:hover{
|
|
||||||
background-color: black;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
.about{
|
|
||||||
width: 100%;
|
|
||||||
height: 1080px;
|
|
||||||
background-image: url("IMG_0210.JPG")}
|
|
||||||
|
|
||||||
.us{
|
|
||||||
position: relative;
|
|
||||||
top: 100px;
|
|
||||||
width: 100%;
|
|
||||||
font-size: 60px;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
@ -0,0 +1,303 @@
|
|||||||
|
from pypinyin import lazy_pinyin,load_single_dict
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
import re
|
||||||
|
import urllib.error,urllib.request
|
||||||
|
import xlwt
|
||||||
|
import json
|
||||||
|
import sqlite3
|
||||||
|
import threading
|
||||||
|
global val
|
||||||
|
val = []
|
||||||
|
|
||||||
|
|
||||||
|
#对于豆瓣top250电影爬取内容的正则表达式
|
||||||
|
findLink = re.compile(r'<a href="(.*?)">')
|
||||||
|
findImgSrc = re.compile(r'<img.*src="(.*?)"',re.S)
|
||||||
|
findTitle = re.compile(r'<span class="title">(.*)</span>')
|
||||||
|
findRating = re.compile(r'<span class="rating_num" property="v:average">(.*)</span>')
|
||||||
|
findJudge = re.compile(r'<span>(\d*)人评价</span>')
|
||||||
|
findBd = re.compile(r'<p class="">(.*?)</p>',re.S)
|
||||||
|
|
||||||
|
|
||||||
|
#对于豆瓣当前某城市正在上映的电影爬取内容的正则表达式
|
||||||
|
findnowmovielink = re.compile(r'.*data-psource="poster" href="(.*?)" target="_blank">',re.S)
|
||||||
|
findnowmovieimg = re.compile(r'src="(.*?)"/>')
|
||||||
|
findnowmovietitle= re.compile(r'data-title="(.*?)"')
|
||||||
|
findnowmovieactors= re.compile(r'data-actors="(.*?)"')
|
||||||
|
findnowmovietime= re.compile(r'data-duration="(.*?)"')
|
||||||
|
findnowmovieregion= re.compile(r'data-region="(.*?)"')
|
||||||
|
findnowmoviedirector= re.compile(r'data-director="(.*?)"')
|
||||||
|
findnowmovieid = re.compile(r'id="(.*?)"')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
a = input("Enter a number: ")
|
||||||
|
if a=="1":
|
||||||
|
baseurl = "https://movie.douban.com/top250?start=" #指定的网页超链接
|
||||||
|
datalist1 = getData1(baseurl) #返回一个装有所有数据的列表
|
||||||
|
savepath = ".\\top250.xls" #存储数据的文档路径
|
||||||
|
saveData1(datalist1,savepath) #存储数据
|
||||||
|
dbpath = "data.db"
|
||||||
|
saveData1DB1(datalist1,dbpath)
|
||||||
|
|
||||||
|
if a=="2":
|
||||||
|
b = input("Enter a city: ")
|
||||||
|
baseurl = "https://movie.douban.com/cinema/nowplaying/" + b + '/'
|
||||||
|
datalist2 = getData2(baseurl)
|
||||||
|
savepath = ".\\citymovies.xls"
|
||||||
|
saveData2(datalist2,savepath)
|
||||||
|
dbpath = "data.db"
|
||||||
|
saveData2DB2(datalist2, dbpath)
|
||||||
|
|
||||||
|
if a=="3": #后台更新柱状图的参数
|
||||||
|
updateCitiesData()
|
||||||
|
|
||||||
|
def multi_thread(usl1):
|
||||||
|
threads = []
|
||||||
|
for i in range(0,10):
|
||||||
|
threads.append(
|
||||||
|
threading.Thread(target = askURL1,args=(usl1+str(i*25),))
|
||||||
|
)
|
||||||
|
for thread in threads:
|
||||||
|
thread.start()
|
||||||
|
for thread in threads:
|
||||||
|
thread.join()
|
||||||
|
# print(threads)
|
||||||
|
return threads
|
||||||
|
|
||||||
|
|
||||||
|
#用于获得数据
|
||||||
|
def getData1(baseurl):
|
||||||
|
global val
|
||||||
|
datalist = [] #将获得的数据装于datalist这个列表
|
||||||
|
multi_thread(baseurl)
|
||||||
|
for j in range(0,10):
|
||||||
|
soup = BeautifulSoup(val[j],"html.parser") #解析
|
||||||
|
for item in soup.find_all('div',class_= "item"):
|
||||||
|
#print(item) #一个测试点
|
||||||
|
data = [] #将每一部电影的具体信息装入data列表
|
||||||
|
item = str(item)
|
||||||
|
link = re.findall(findLink,item)[0] #详情链接
|
||||||
|
data.append(link)
|
||||||
|
imgSrc = re.findall(findImgSrc,item)[0] #图片链接
|
||||||
|
data.append(imgSrc)
|
||||||
|
titles = re.findall(findTitle,item) #标题
|
||||||
|
if(len(titles) == 2 ):
|
||||||
|
ctitle = titles[0]
|
||||||
|
data.append(ctitle)
|
||||||
|
otitle = titles[1].replace("/","")
|
||||||
|
data.append(otitle)
|
||||||
|
else:
|
||||||
|
data.append(titles[0])
|
||||||
|
data.append(" ")
|
||||||
|
rating = re.findall(findRating,item)[0] #评分
|
||||||
|
data.append(rating)
|
||||||
|
judgeNum = re.findall(findJudge,item)[0] #评分人数
|
||||||
|
data.append(judgeNum)
|
||||||
|
bd = re.findall(findBd,item)[0] #概要
|
||||||
|
bd = re.sub('\s',"",bd)
|
||||||
|
bd = re.sub(r'/',"",bd)
|
||||||
|
bd = re.sub('<br>',"",bd)
|
||||||
|
data.append(bd.strip())
|
||||||
|
datalist.append(data) #将data列表装入datalist列表
|
||||||
|
print(datalist)
|
||||||
|
return datalist
|
||||||
|
|
||||||
|
def getData2(baseurl):
|
||||||
|
datalist = [] #将获得的数据装于datalist这个列表
|
||||||
|
html = askURL2(baseurl)
|
||||||
|
soup = BeautifulSoup(html,"html.parser") #解析
|
||||||
|
for item in soup.find_all('li',class_= "list-item"): #一个测试点
|
||||||
|
data = [] #将每一部电影的具体信息装入data列表
|
||||||
|
item = str(item)
|
||||||
|
link = re.findall(findnowmovielink,item)[0]
|
||||||
|
data.append(link)
|
||||||
|
img = re.findall(findnowmovieimg,item)[0]
|
||||||
|
data.append(img)
|
||||||
|
title = re.findall(findnowmovietitle,item)[0]
|
||||||
|
data.append(title)
|
||||||
|
director = re.findall(findnowmoviedirector, item)[0]
|
||||||
|
data.append(director)
|
||||||
|
actors = re.findall(findnowmovieactors,item)[0]
|
||||||
|
data.append(actors)
|
||||||
|
time = re.findall(findnowmovietime, item)[0]
|
||||||
|
data.append(time)
|
||||||
|
region = re.findall(findnowmovieregion, item)[0]
|
||||||
|
data.append(region)
|
||||||
|
id = re.findall(findnowmovieid,item)[0]
|
||||||
|
data.append(id)
|
||||||
|
datalist.append(data) #将data列表装入datalist列表
|
||||||
|
return datalist
|
||||||
|
|
||||||
|
#用来得到一个指定URL的网页内容(豆瓣top250)
|
||||||
|
def askURL1(url):
|
||||||
|
#伪装为浏览器
|
||||||
|
global val
|
||||||
|
head = {
|
||||||
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Safari/537.36 Edg/99.0.1150.55"
|
||||||
|
}
|
||||||
|
resquest = urllib.request.Request(url,headers=head)
|
||||||
|
html = ""
|
||||||
|
try:
|
||||||
|
response = urllib.request.urlopen(resquest)
|
||||||
|
html = response.read().decode("utf-8")
|
||||||
|
#print(html)
|
||||||
|
except urllib.error.URLError as e:
|
||||||
|
if hasattr(e,"code"):
|
||||||
|
print(e.code)
|
||||||
|
if hasattr(e,"reason"):
|
||||||
|
print(e.reason)
|
||||||
|
val.append(html)
|
||||||
|
# print(html)
|
||||||
|
# return html
|
||||||
|
|
||||||
|
def askURL2(url):
|
||||||
|
# 伪装为浏览器
|
||||||
|
head = {
|
||||||
|
"User-Agent": " Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36 Edg/100.0.1185.36"
|
||||||
|
}
|
||||||
|
resquest = urllib.request.Request(url, headers=head)
|
||||||
|
html = ""
|
||||||
|
try:
|
||||||
|
response = urllib.request.urlopen(resquest)
|
||||||
|
html = response.read().decode("utf-8")
|
||||||
|
# print(html)
|
||||||
|
except urllib.error.URLError as e:
|
||||||
|
if hasattr(e, "code"):
|
||||||
|
print(e.code)
|
||||||
|
if hasattr(e, "reason"):
|
||||||
|
print(e.reason)
|
||||||
|
return html
|
||||||
|
|
||||||
|
def init_tb1(dbpath):
|
||||||
|
sql = '''
|
||||||
|
create table if not exists movie250
|
||||||
|
(
|
||||||
|
info_link text,
|
||||||
|
pic_link text,
|
||||||
|
cname varchar ,
|
||||||
|
ename varchar ,
|
||||||
|
score numeric ,
|
||||||
|
rated numeric ,
|
||||||
|
info text
|
||||||
|
)
|
||||||
|
'''
|
||||||
|
conn = sqlite3.connect(dbpath)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
cursor.execute(sql)
|
||||||
|
cursor.execute("delete from movie250 where 1=1;")
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
def init_tb2(dbpath):
|
||||||
|
sql = '''
|
||||||
|
create table if not exists citymovies
|
||||||
|
(
|
||||||
|
link text,
|
||||||
|
img text,
|
||||||
|
title varchar ,
|
||||||
|
director varchar ,
|
||||||
|
actors varchar ,
|
||||||
|
times varchar ,
|
||||||
|
region varchar ,
|
||||||
|
id varchar
|
||||||
|
)
|
||||||
|
'''
|
||||||
|
conn = sqlite3.connect(dbpath)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute(sql)
|
||||||
|
cursor.execute("delete from citymovies where 1=1;")
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
def saveData1DB1(datalist,dbpath):
|
||||||
|
init_tb1(dbpath)
|
||||||
|
conn = sqlite3.connect(dbpath)
|
||||||
|
cur = conn.cursor()
|
||||||
|
for data in datalist:
|
||||||
|
for index in range(len(data)):
|
||||||
|
if index == 4 or index == 5:
|
||||||
|
continue
|
||||||
|
data[index] = '"'+data[index].strip()+'"'
|
||||||
|
sql = '''
|
||||||
|
insert into movie250(info_link,pic_link,cname,ename,score,rated,info)
|
||||||
|
values(%s)'''%",".join(data)
|
||||||
|
|
||||||
|
cur.execute(sql)
|
||||||
|
conn.commit()
|
||||||
|
cur.close()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
def saveData2DB2(datalist,dbpath):
|
||||||
|
init_tb2(dbpath)
|
||||||
|
conn = sqlite3.connect(dbpath)
|
||||||
|
cur = conn.cursor()
|
||||||
|
for data in datalist:
|
||||||
|
for index in range(len(data)):
|
||||||
|
data[index] = '"'+data[index].strip()+'"'
|
||||||
|
sql = '''
|
||||||
|
insert into citymovies(link,img,title,director,actors,times,region,id)
|
||||||
|
values(%s)'''%",".join(data)
|
||||||
|
|
||||||
|
|
||||||
|
cur.execute(sql)
|
||||||
|
conn.commit()
|
||||||
|
cur.close()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
def saveData1(datalist,savepath):
|
||||||
|
print("save...")
|
||||||
|
book = xlwt.Workbook(encoding="utf-8",style_compression=0)
|
||||||
|
sheet = book.add_sheet("豆瓣电影Top250",cell_overwrite_ok=True)
|
||||||
|
col = ("电影详情链接","图片链接","影片中文名字","影片外国名字","评分","评价数","相关信息")
|
||||||
|
for i in range(0,7):
|
||||||
|
sheet.write(0,i,col[i])
|
||||||
|
for i in range(0,250):
|
||||||
|
print("第%d条"%(i+1))
|
||||||
|
data = datalist[i]
|
||||||
|
for j in range(0,7):
|
||||||
|
sheet.write(i,j,data[j])
|
||||||
|
book.save(savepath)
|
||||||
|
|
||||||
|
def saveData2(datalist,savepath):
|
||||||
|
print("save...")
|
||||||
|
book = xlwt.Workbook(encoding="utf-8",style_compression=0)
|
||||||
|
sheet = book.add_sheet("豆瓣电影Top250",cell_overwrite_ok=True)
|
||||||
|
col = ("电影详情链接","图片链接","影片中文名字","导演","演员","时长","制片地区","电影id")
|
||||||
|
for i in range(0,8):
|
||||||
|
sheet.write(0,i,col[i])
|
||||||
|
for i in range(len(datalist)):
|
||||||
|
print("第%d条"%(i+1))
|
||||||
|
data = datalist[i]
|
||||||
|
for j in range(0,8):
|
||||||
|
sheet.write(i,j,data[j])
|
||||||
|
book.save(savepath)
|
||||||
|
|
||||||
|
def updateCitiesData(): #用于后台更新柱状图的参数
|
||||||
|
f = open("./static/assets/json/citiesData.json", "r" ,encoding = "utf-8")
|
||||||
|
data_dict = (dict(json.load(f)))
|
||||||
|
|
||||||
|
print(data_dict)
|
||||||
|
feature_list = data_dict["features"]
|
||||||
|
load_single_dict({ord('重'): 'chong'})
|
||||||
|
for item in feature_list:
|
||||||
|
|
||||||
|
item["properties"]["名称"] = "".join(lazy_pinyin(item["properties"]["名称"]))
|
||||||
|
|
||||||
|
cityname = item["properties"]["名称"][0:len(item["properties"]["名称"]) - 3]
|
||||||
|
|
||||||
|
print(cityname+':', end=" ")
|
||||||
|
|
||||||
|
item["properties"]["Yuanxian"] = len(getData2("https://movie.douban.com/cinema/nowplaying/" + cityname + '/'))
|
||||||
|
print(item["properties"]["Yuanxian"])
|
||||||
|
|
||||||
|
f.close()
|
||||||
|
f = open("./static/assets/json/citiesData.json", "w", encoding="GBK")
|
||||||
|
json.dump(data_dict,f)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
print("爬取完成!")
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@ -0,0 +1,171 @@
|
|||||||
|
/**
|
||||||
|
* Template Name: Mamba - v2.0.1
|
||||||
|
* Template URL: https://bootstrapmade.com/mamba-one-page-bootstrap-template-free/
|
||||||
|
* Author: BootstrapMade.com
|
||||||
|
* License: https://bootstrapmade.com/license/
|
||||||
|
*/
|
||||||
|
!(function($) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
// Toggle .header-scrolled class to #header when page is scrolled
|
||||||
|
$(window).scroll(function() {
|
||||||
|
if ($(this).scrollTop() > 100) {
|
||||||
|
$('#header').addClass('header-scrolled');
|
||||||
|
} else {
|
||||||
|
$('#header').removeClass('header-scrolled');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if ($(window).scrollTop() > 100) {
|
||||||
|
$('#header').addClass('header-scrolled');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stick the header at top on scroll
|
||||||
|
$("#header").sticky({
|
||||||
|
topSpacing: 0,
|
||||||
|
zIndex: '50'
|
||||||
|
});
|
||||||
|
|
||||||
|
// Smooth scroll for the navigation menu and links with .scrollto classes
|
||||||
|
$(document).on('click', '.nav-menu a, .mobile-nav a, .scrollto', function(e) {
|
||||||
|
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
|
||||||
|
e.preventDefault();
|
||||||
|
var target = $(this.hash);
|
||||||
|
if (target.length) {
|
||||||
|
|
||||||
|
var scrollto = target.offset().top;
|
||||||
|
var scrolled = 2;
|
||||||
|
|
||||||
|
if ($('#header-sticky-wrapper').length) {
|
||||||
|
scrollto -= $('#header-sticky-wrapper').outerHeight() - scrolled;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($(this).attr("href") == '#header') {
|
||||||
|
scrollto = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$('html, body').animate({
|
||||||
|
scrollTop: scrollto
|
||||||
|
}, 1500, 'easeInOutExpo');
|
||||||
|
|
||||||
|
if ($(this).parents('.nav-menu, .mobile-nav').length) {
|
||||||
|
$('.nav-menu .active, .mobile-nav .active').removeClass('active');
|
||||||
|
$(this).closest('li').addClass('active');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($('body').hasClass('mobile-nav-active')) {
|
||||||
|
$('body').removeClass('mobile-nav-active');
|
||||||
|
$('.mobile-nav-toggle i').toggleClass('icofont-navigation-menu icofont-close');
|
||||||
|
$('.mobile-nav-overly').fadeOut();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Mobile Navigation
|
||||||
|
if ($('.nav-menu').length) {
|
||||||
|
var $mobile_nav = $('.nav-menu').clone().prop({
|
||||||
|
class: 'mobile-nav d-lg-none'
|
||||||
|
});
|
||||||
|
$('body').append($mobile_nav);
|
||||||
|
$('body').prepend('<button type="button" class="mobile-nav-toggle d-lg-none"><i class="icofont-navigation-menu"></i></button>');
|
||||||
|
$('body').append('<div class="mobile-nav-overly"></div>');
|
||||||
|
|
||||||
|
$(document).on('click', '.mobile-nav-toggle', function(e) {
|
||||||
|
$('body').toggleClass('mobile-nav-active');
|
||||||
|
$('.mobile-nav-toggle i').toggleClass('icofont-navigation-menu icofont-close');
|
||||||
|
$('.mobile-nav-overly').toggle();
|
||||||
|
});
|
||||||
|
|
||||||
|
$(document).on('click', '.mobile-nav .drop-down > a', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
$(this).next().slideToggle(300);
|
||||||
|
$(this).parent().toggleClass('active');
|
||||||
|
});
|
||||||
|
|
||||||
|
$(document).click(function(e) {
|
||||||
|
var container = $(".mobile-nav, .mobile-nav-toggle");
|
||||||
|
if (!container.is(e.target) && container.has(e.target).length === 0) {
|
||||||
|
if ($('body').hasClass('mobile-nav-active')) {
|
||||||
|
$('body').removeClass('mobile-nav-active');
|
||||||
|
$('.mobile-nav-toggle i').toggleClass('icofont-navigation-menu icofont-close');
|
||||||
|
$('.mobile-nav-overly').fadeOut();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else if ($(".mobile-nav, .mobile-nav-toggle").length) {
|
||||||
|
$(".mobile-nav, .mobile-nav-toggle").hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intro carousel
|
||||||
|
var heroCarousel = $("#heroCarousel");
|
||||||
|
var heroCarouselIndicators = $("#hero-carousel-indicators");
|
||||||
|
heroCarousel.find(".carousel-inner").children(".carousel-item").each(function(index) {
|
||||||
|
(index === 0) ?
|
||||||
|
heroCarouselIndicators.append("<li data-target='#heroCarousel' data-slide-to='" + index + "' class='active'></li>"):
|
||||||
|
heroCarouselIndicators.append("<li data-target='#heroCarousel' data-slide-to='" + index + "'></li>");
|
||||||
|
});
|
||||||
|
|
||||||
|
heroCarousel.on('slid.bs.carousel', function(e) {
|
||||||
|
$(this).find('h2').addClass('animated fadeInDown');
|
||||||
|
$(this).find('p').addClass('animated fadeInUp');
|
||||||
|
$(this).find('.btn-get-started').addClass('animated fadeInUp');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Back to top button
|
||||||
|
$(window).scroll(function() {
|
||||||
|
if ($(this).scrollTop() > 100) {
|
||||||
|
$('.back-to-top').fadeIn('slow');
|
||||||
|
} else {
|
||||||
|
$('.back-to-top').fadeOut('slow');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.back-to-top').click(function() {
|
||||||
|
$('html, body').animate({
|
||||||
|
scrollTop: 0
|
||||||
|
}, 1500, 'easeInOutExpo');
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Initiate the venobox plugin
|
||||||
|
$(window).on('load', function() {
|
||||||
|
$('.venobox').venobox();
|
||||||
|
});
|
||||||
|
|
||||||
|
// jQuery counterUp
|
||||||
|
$('[data-toggle="counter-up"]').counterUp({
|
||||||
|
delay: 10,
|
||||||
|
time: 1000
|
||||||
|
});
|
||||||
|
|
||||||
|
// Porfolio isotope and filter
|
||||||
|
$(window).on('load', function() {
|
||||||
|
var portfolioIsotope = $('.portfolio-container').isotope({
|
||||||
|
itemSelector: '.portfolio-item',
|
||||||
|
layoutMode: 'fitRows'
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#portfolio-flters li').on('click', function() {
|
||||||
|
$("#portfolio-flters li").removeClass('filter-active');
|
||||||
|
$(this).addClass('filter-active');
|
||||||
|
|
||||||
|
portfolioIsotope.isotope({
|
||||||
|
filter: $(this).data('filter')
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Initiate venobox (lightbox feature used in portofilo)
|
||||||
|
$(document).ready(function() {
|
||||||
|
$('.venobox').venobox();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Initi AOS
|
||||||
|
AOS.init({
|
||||||
|
duration: 1000,
|
||||||
|
easing: "ease-in-out-back"
|
||||||
|
});
|
||||||
|
|
||||||
|
})(jQuery);
|
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@ -1,79 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>主页</title>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="css1.css">/*连接CSS*/
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="topnav">
|
|
||||||
<a href="#">主页</a>
|
|
||||||
<a href="#playing">正在热映</a>
|
|
||||||
<a href="#">即将上映</a>
|
|
||||||
<a href="#">TOP榜</a>
|
|
||||||
<a href="#download">下载</a>
|
|
||||||
<a href="#about">关于我们</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="header" id = "header">
|
|
||||||
<p>Python爬虫研究站</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="introduction">
|
|
||||||
<div class = "title">
|
|
||||||
<p>
|
|
||||||
在这里,可以爬取有关最近影视的相关信息。
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<a class = "try" href = "#playing">尝试一下</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class = "playing" id = "playing">
|
|
||||||
<div>
|
|
||||||
<p class="lable">
|
|
||||||
键入以搜索你想要的电影:
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div class = "searching" id = "searching">
|
|
||||||
<ul>
|
|
||||||
<li>
|
|
||||||
<input type="text" id = "name" name = "name">
|
|
||||||
</li>
|
|
||||||
<li class="searching_logo">
|
|
||||||
<button>🔍</button>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id = "frame">
|
|
||||||
<iframe></iframe>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class = "showing">
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="download" id = "download">
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class = "about" id = "about">
|
|
||||||
<div>
|
|
||||||
<p class = "us">关于我们</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
@ -0,0 +1,39 @@
|
|||||||
|
import jieba
|
||||||
|
from matplotlib import pyplot as plt
|
||||||
|
from wordcloud import WordCloud
|
||||||
|
from PIL import Image
|
||||||
|
import numpy as np
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
|
def makeWordcloud(image_name):
|
||||||
|
con = sqlite3.connect('data.db')
|
||||||
|
cur = con.cursor()
|
||||||
|
sql = 'select info from movie250 '
|
||||||
|
data = cur.execute(sql)
|
||||||
|
text = ""
|
||||||
|
for item in data:
|
||||||
|
text = text + item[0]
|
||||||
|
cur.close()
|
||||||
|
con.close()
|
||||||
|
cut = jieba.cut(text)
|
||||||
|
string = ' '.join(cut)
|
||||||
|
img = Image.open(image_name)
|
||||||
|
img_array = np.array(img)
|
||||||
|
wc = WordCloud(
|
||||||
|
# background_color = 'white',
|
||||||
|
# mask = img_array,
|
||||||
|
# font_path = 'simsun.ttc'
|
||||||
|
font_path="msyhbd.ttc",
|
||||||
|
mask=img_array,
|
||||||
|
width=1500,
|
||||||
|
height=1000,
|
||||||
|
background_color="white",
|
||||||
|
min_font_size=5,
|
||||||
|
max_font_size=120,
|
||||||
|
max_words=600
|
||||||
|
)
|
||||||
|
wc.generate_from_text(string)
|
||||||
|
fig = plt.figure(1)
|
||||||
|
plt.imshow(wc)
|
||||||
|
plt.axis('off')
|
||||||
|
plt.savefig('output.jpg', dpi=1600)
|
Loading…
Reference in new issue