Python XML API 请求 Linux cmd returns 输出请求的详细信息。有没有办法隐藏或不接收它?
Python XML API request on Linux cmd returns output with request's detail. Is there a way to hide or not receive it?
示例如下:
query_state = "curl -k --location -g --request GET 'https://hostname/api/?type=op&cmd=<show><state></state></show>&key=API-KEY'"
get_state = os.popen(query_state).read()
soup = BeautifulSoup(get_state, 'lxml')
state = soup.find('state').string
print(state)
这是输出:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 4538 100 4538 0 0 27840 0 --:--:-- --:--:-- --:--:-- 27840
active
我只需要 'active' 这很好,但是拒绝请求查看?
我试过:
get_state = os.system(query_state)
但无法将输出分配给变量。
您可以使用 curl --silent
标志隐藏详细输出。
示例如下:
query_state = "curl -k --location -g --request GET 'https://hostname/api/?type=op&cmd=<show><state></state></show>&key=API-KEY'"
get_state = os.popen(query_state).read()
soup = BeautifulSoup(get_state, 'lxml')
state = soup.find('state').string
print(state)
这是输出:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 4538 100 4538 0 0 27840 0 --:--:-- --:--:-- --:--:-- 27840
active
我只需要 'active' 这很好,但是拒绝请求查看?
我试过:
get_state = os.system(query_state)
但无法将输出分配给变量。
您可以使用 curl --silent
标志隐藏详细输出。