当前位置:网站首页>The crawler is encapsulated into an api
The crawler is encapsulated into an api
2022-08-11 10:02:00 【Born to be a worm】
from flask import Flask, g
from flask_restful import reqparse, Api, Resource
from flask_httpauth import HTTPTokenAuth
from spider_yingshang import spider # This part is the crawler function
# FlaskRelated variable declarations
app = Flask(__name__)
api = Api(app)
# RESTfulAPI的参数解析 -- put / post参数解析
parser_put = reqparse.RequestParser()
# parser_put.add_argument("user", type=str, required=True, help="need user data")
# parser_put.add_argument("pwd", type=str, required=True, help="need pwd data")
parser_put.add_argument("keyword", type=str, required=True, help="need keyword data")
# # This part is the crawler function
# def to_do(arg1, args2):
# return "this is info"
# 操作(post / get)资源列表
class TodoList(Resource):
def post(self):
""" 添加一个新用户: curl http://127.0.0.1:5000/users -X POST -d "name=Brown&age=20" -H "Authorization: token fejiasdfhu" """
args = parser_put.parse_args()
# # Build new users
# user = args['user']
# pwd = args['pwd']
# info = {"info": to_do(user, pwd)}
keyword = args['keyword']
info = {
"info": spider(keyword)}
# Resource added successfully,返回201
return info, 201
# 设置路由,That is, the routing address is http://127.0.0.1:5000/users
api.add_resource(TodoList, "/search")
if __name__ == "__main__":
app.run(debug=True)
请求接口结果:
参考:https://blog.csdn.net/t8116189520/article/details/80179221
边栏推荐
- 自定义卷积核的分组转置卷积如何实现?
- 代码签名证书可以解决软件被杀毒软件报毒提醒吗?
- > 家乡旅游景点网页作业制作 网页代码运用了DIV盒子的使用方法,如盒子的嵌套、浮动、margin、border、backgro
- 分割学习(loss and Evaluation)
- 保证金监控中心保证期货开户和交易记录
- MongoDB 非关系型数据库
- 数据库 SQL 优化大总结之:百万级数据库优化方案
- OAK-FFC Series Product Getting Started Guide
- VC6.0 +WDK 开发驱动的环境配置
- What is the difference between the qspi interface and the ordinary four-wire SPI interface?
猜你喜欢
随机推荐
MongoDB 非关系型数据库
idea插件自动填充setter
Convolutional Neural Network System,Convolutional Neural Network Graduation Thesis
unity初级面试分享
[UE] 入坑
Open Office XML 格式中的 Style 设计原理
全新FIDE 编译简单评测
工业检测深度学习方法综述
HDRP shader 获取阴影(Custom Pass)
联想 U 盘装机后出现 start pxe over ipv4
零基础创作专业wordpress网站12-设置标签栏图标(favicon)
【无标题】超时超时超时超时超时
【luogu CF1427F】Boring Card Game(贪心)(性质)
Oacle数据库使用问题
OAK-FFC系列产品上手指南
【Prometheus】Alertmanager告警全方位讲解
wordpress插件开发03-简单的all in one seo 插件开发
Primavera Unifier advanced formula usage sharing
力扣打卡----打家劫舍
snapshot standby切换