|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
import middlewares
|
|
|
|
|
import settings
|
|
|
|
|
import view
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def showBanner(menu = 'main'):
|
|
|
|
|
print(settings.BANNER.get(menu), end='')
|
|
|
|
|
|
|
|
|
|
def switch(menu = '1'):
|
|
|
|
|
case = {
|
|
|
|
|
'1' : main,
|
|
|
|
|
'2' : introduce,
|
|
|
|
|
'3' : View,
|
|
|
|
|
'4' : middlewares.save2Redis,
|
|
|
|
|
'5' : middlewares.clearRedis,
|
|
|
|
|
'6' : milkSpider,
|
|
|
|
|
'7' : aexit
|
|
|
|
|
}
|
|
|
|
|
if menu in case.keys():
|
|
|
|
|
case.get(menu)()
|
|
|
|
|
else:
|
|
|
|
|
print("no such choice", end = '')
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
def introduce():
|
|
|
|
|
print(settings.BANNER.get('introduce'), end = '')
|
|
|
|
|
while True:
|
|
|
|
|
print("请输入:", end = '')
|
|
|
|
|
select = str(input())
|
|
|
|
|
if select == "r":
|
|
|
|
|
return
|
|
|
|
|
else:
|
|
|
|
|
print("invaild choice!")
|
|
|
|
|
|
|
|
|
|
def View():
|
|
|
|
|
view.main()
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
def milkSpider():
|
|
|
|
|
|
|
|
|
|
dir = 'Catalogues'
|
|
|
|
|
if os.path.exists(dir):
|
|
|
|
|
if len(os.listdir(dir)):
|
|
|
|
|
print("检测到缓存目录下已有数据,调用milkSpider将有可能导致数据重复和冗余。")
|
|
|
|
|
|
|
|
|
|
print("注意:调用milkSpider将启动selenium以及requests进程,因为爬取数据量较大,往往会占用较多时间,确定吗?[c]continue or [q]quit:", end = '')
|
|
|
|
|
flag = str(input())
|
|
|
|
|
if flag == "q":
|
|
|
|
|
print("取消")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
if middlewares.precheck():
|
|
|
|
|
start_time = time.time()
|
|
|
|
|
middlewares.mainThread()
|
|
|
|
|
print("Totally spend " + str(round(time.time() - start_time, 2)) + " seconds")
|
|
|
|
|
print("milkSpider done.")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
def aexit():
|
|
|
|
|
print("bye!")
|
|
|
|
|
exit()
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
while True:
|
|
|
|
|
showBanner()
|
|
|
|
|
menu = str(input("选择一项:"))
|
|
|
|
|
switch(menu)
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
# milkSpider()
|
|
|
|
|
main()
|