我已经编写了这段代码,它应该上传一些东西,但是它不上传任何东西,只是在控制台中打印命令的结果,并且不向网站加载任何东西
import requests, os, re, subprocess
from bs4 import BeautifulSoup
command = 'netsh interface ip show addresses "Ethernet" | findstr /c:IP'
outcome = str(subprocess.Popen(command, shell=True).wait())
#soup = BeautifulSoup(outcome,'lxml')
#outcome = outcome.replace('0','')
#print str(subprocess.call(command, shell=True))
requests.post("example.com", {'field1': outcome})
和控制台输出:
IP Address: 192.168.1.23
将0上传到网站
我尝试过:
import requests, os, re, subprocess
from bs4 import BeautifulSoup
command = 'netsh interface ip show addresses "Ethernet" | findstr /c:IP'
#subprocess.communicate(command, shell=True)
subprocess.Popen(command, shell=True).communicate()
outcome = subprocess.PIPE
#soup = BeautifulSoup(outcome,'lxml')
#outcome = outcome.replace('0','')
#print str(subprocess.call(command, shell=True))
requests.post("example.com", {'field1': outcome})
和控制台输出:
IP Address: 192.168.1.23
已上传到网站-1
我想要做的是将IP地址结果上传到网站。
答案 0 :(得分:0)
您没有正确使用子流程。我建议您使用outputfile:
v1\nv2\nv3
,并传入stdout = subprocess.PIPE来实际获取子进程的stdout。
subprocess.Popen.communicate