接口获取数据

注意json格式的转换和data中[]符号不能缺

方式一:

1
2
3
4
5
import requests,json
url = 'http://192.168.0.226:9557/api/internal/findQxbInfo'
data = {"company":["华为技术有限公司"]}
result = requests.post(url,json.dumps(data))
result.text

方式二:(一的提升)

1
2
3
4
5
6
7
import requests,json
url = 'http://192.168.0.226:9557/api/internal/findQxbInfo'
data = {'company':["华为技术有限公司"]}
headers = {'Content-type':'application/json'}
data = json.dumps(data)
result = requests.post(url,data,headers)
json.loads(result.text)

获取公司曾用名和现用名接口操作

1
2
3
4
5
6
zl_list = []
for applicant in applicant_list:
url = f'http://192.168.0.226:9666/api/search/patentStatisticData?companyName={applicant}'
result = requests.get(url)
inventionNum = json.loads(result.text)['result']['inventionNum']
zl_list.append([applicant,inventionNum])

python flask写接口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from flask import request, Flask, jsonify
from http import client

client.HTTPConnection._http_vsn = 10
client.HTTPConnection._http_vsn_str = 'HTTP/1.0'

app = Flask(__name__)
app.config['JSON_AS_ASCII'] = False



@app.route('/test', methods=['POST'])
def post_Data():
try:
info = request.json
app_texts = info['app_texts']
except:
result = {'FlagCode':0,'message':'格式错误'}
return jsonify(result)
if type(app_texts) != list:
result = {'FlagCode':0,'message':'格式错误'}
return jsonify(result)
if app_texts == []:
result = {'FlagCode':0,'message':'缺少数据'}
return jsonify(result)
#查数据写成对应格式
result = {'FlagCode':1,'message':'操作成功','result':res}
return jsonify(result)


if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=9525)