当前位置:网站首页>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
边栏推荐
猜你喜欢
神经痛分类图片大全,神经病理性疼痛分类
php将form表单内容提交到数据库后中文变成??(问号)
The mathematical knowledge required for neural networks, the mathematical foundation of neural networks
期货开户最低的是交易所手续费不加佣金
[UE] 入坑
HDRP shader to get shadows (Custom Pass)
华为WLAN技术:AC/AP 实验
【剑指offer】左旋字符串,替换空格,还有类题!!!
PowerMock for Systematic Explanation of Unit Testing
How to use QTableWidget
随机推荐
WordpressCMS主题开发01-首页制作
idea插件自动填充setter
Network model (U - net, U - net++, U - net++ +)
中移链EOSJS实战使用
1002 A+B for Polynomials
全新FIDE 编译简单评测
MySQL表sql语句增删查改_增加
canvas图片操作
模型训练出现NAN
华为WLAN技术:AC/AP 实验
数据中台方案分析和发展方向
WooCommerce Ecommerce WordPress Plugin - Make American Money
VC6.0 +WDK 开发驱动的环境配置
最强大脑(9)
爬虫封装成api
Primavera P6 Professional 21.12 Login exception case sharing
【Prometheus】 Grafana数据与可视化
你觉得程序员是一个需要天赋的职业吗?
训练一个神经网络要多久,神经网络训练时间过长
数据库 SQL 优化大总结之:百万级数据库优化方案