当前位置:网站首页>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
边栏推荐
猜你喜欢

卷积神经网络梯度消失,神经网络中梯度的概念

神经痛分类图片大全,神经病理性疼痛分类

Simple interaction between server and client

WooCommerce Ecommerce WordPress Plugin - Make American Money

保证金监控中心保证期货开户和交易记录

神经网络需要的数学知识,神经网络的数学基础

HDRP shader 获取阴影(Custom Pass)

Primavera P6 Professional 21.12 Login exception case sharing

canvas文字绘制(大小、粗体、倾斜、对齐、基线)

神经网络参数如何确定的,神经网络参数个数计算
随机推荐
Primavera Unifier 高级公式使用分享
opencv 制作趣图
使用stream实现两个list集合的合并(对象属性的合并)
canvas文字绘制(大小、粗体、倾斜、对齐、基线)
idea插件自动填充setter
OAK-FFC Series Product Getting Started Guide
大家有遇到这种错吗?flink-sql 写入 clickhouse
MongoDB 非关系型数据库
Convolutional Neural Network System,Convolutional Neural Network Graduation Thesis
The mathematical knowledge required for neural networks, the mathematical foundation of neural networks
MySQL表sql语句增删查改_增加
最强大脑(9)
自定义卷积核的分组转置卷积如何实现?
分割学习(loss and Evaluation)
模型训练出现NAN
MySQL约束
SQL statement
神经网络参数如何确定的,神经网络参数个数计算
How to use QTableWidget
困扰所有SAP顾问多年的问题终于解决了