用于文本搜索的Python REST服务API

2024-04-25 17:54:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我是新的外部脚本服务现在。你知道吗

我现在有一个执行文本搜索服务的要求。我计划在csv文件中插入要搜索的文本,然后通过python restapi服务执行文本搜索。你知道吗

但是,我找不到任何直接的python REST服务API来进行文本搜索。有人知道做这项工作的其他方法吗?你知道吗

提前谢谢!你知道吗


Tags: 文件csv方法文本脚本restapirestapi
1条回答
网友
1楼 · 发布于 2024-04-25 17:54:05

您可以在ServiceNow平台中使用“全局文本搜索API”来获取搜索结果。首先,您需要获得可用的搜索组列表,然后发送一个包含需要搜索的组列表和搜索关键字的查询。你知道吗

下面是一个在知识库和服务目录中搜索关键字代理的示例程序。你知道吗

import requests

# Set the request parameters
url = 'https://<instance>.service-now.com/api/now/v1/globalsearch/groups'

# Eg. User name="admin", Password="admin" for this code sample.
user = 'admin'
pwd = 'admin'

# Set proper headers
headers = {"Content-Type":"application/json","Accept":"application/json"}

# Do the HTTP request
response = requests.get(url, auth=(user, pwd), headers=headers )

# Check for HTTP codes other than 200
if response.status_code != 200: 
    print('Status:', response.status_code, 'Headers:', response.headers, 'Error Response:',response.json())
    exit()

# Decode the JSON response into a dictionary and use the data
data = response.json()
print(data)

url = 'https://<instance>.service-now.com/api/now/v1/globalsearch/search?sysparm_groups=2b77ce594bd6c0d901b8fbe25ceff671&sysparm_search=agent'

# Do the HTTP request
response = requests.get(url, auth=(user, pwd), headers=headers )

# Check for HTTP codes other than 200
if response.status_code != 200: 
    print('Status:', response.status_code, 'Headers:', response.headers, 'Error Response:',response.json())
    exit()

# Decode the JSON response into a dictionary and use the data
data = response.json()
print(data)

相关问题 更多 >