from flask import * from flask_restful import Api, Resource, reqparse from selenium import webdriver from lxml import etree import os import re import logging import random from logging.handlers import RotatingFileHandler
app = Flask(__name__) api = Api(app)
class infoView(Resource):
??? def post(self): ??????? parser = reqparse.RequestParser()? # 对reqparse模块下的RequestParser类进行实例化 ??????? parser.add_argument('asin', type=str)? # add_argument方法添加接收参数 ??????? args = parser.parse_args()? # 解析参数 ??????? res = infoView.selenium_run(self, args["url"]) ??????? return res
??? # 启动浏览器 ??? def selenium_run(self, url): ??????????? result = {"code": 200, "data": "data", "msg":"success"} ??????????? return result
api.add_resource(infoView, '/keyword') if __name__ == '__main__': ??? logFormatStr = '[%(asctime)s] p%(process)s {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s' ??? logging.basicConfig(format=logFormatStr, filename="global.log", level=logging.DEBUG) ??? formatter = logging.Formatter(logFormatStr, '%m-%d %H:%M:%S') ??? fileHandler = logging.FileHandler("summary.log") ??? fileHandler.setLevel(logging.DEBUG) ??? fileHandler.setFormatter(formatter) ??? streamHandler = logging.StreamHandler() ??? streamHandler.setLevel(logging.DEBUG) ??? streamHandler.setFormatter(formatter) ??? app.logger.addHandler(fileHandler) ??? app.logger.addHandler(streamHandler) ??? app.logger.info("Logging is set up.")
??? app.run(host='0.0.0.0', port=6088, debug=True) ??? app.logger.info('项目启动: ')
|