我正在尝试检查 t 是否等于“HTTP/1.1 200 OK”
import os
t = os.system("curl -Is onepage.com | head -1")
print(t)
但我从 os.system 得到的回应是
HTTP/1.1 200 OK
0
我不知道如何去掉那个 0,我试过了x = subprocess.check_output(['curl -Is onepage.com | head -1']),但它给了我这个错误:
Traceback (most recent call last):
File "teste.py", line 3, in <module>
x = check_output(['curl -Is onepage.com | head -1'])
File "/usr/lib/python3.8/subprocess.py", line 411, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "/usr/lib/python3.8/subprocess.py", line 489, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib/python3.8/subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.8/subprocess.py", line 1702, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'curl -Is onepage.com | head -1'
慕桂英3389331
相关分类