linux怎么从外部传递一个url链接到Python脚本
#!/usr/bin/pythonimportrequestsimportsysroot_url='链接'header={'User-Agent':'echoios5.1...
#!/usr/bin/python
import requests
import sys
root_url = '链接'
header = { 'User-Agent' : 'echo ios 5.1 20160417;Mrack' }
reload(sys)
sys.setdefaultencoding('utf-8')
s = requests.session()
response = s.get(root_url,headers = header)
print response.text.encode('utf-8')
如上 怎么从外部传入一个链接到py脚本内 展开
import requests
import sys
root_url = '链接'
header = { 'User-Agent' : 'echo ios 5.1 20160417;Mrack' }
reload(sys)
sys.setdefaultencoding('utf-8')
s = requests.session()
response = s.get(root_url,headers = header)
print response.text.encode('utf-8')
如上 怎么从外部传入一个链接到py脚本内 展开
1个回答
2016-05-16
展开全部
http client -> web容器 -> subprosess +ssh 或 telnet ->获取stdout stderr -》web容器->http client
或者使用paramiko
import paramiko
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.load_system_host_keys()
client.connect(SERVER_HOSTNAME, port=SERVER_PORT, username=SERVER_USERNAME, password=SERVER_PASSWORD)
_,stdout,_ = client.exec_command("ls -lh --color", 10240)
outputLines = stdout.readlines()
outputLines = "".join(outputLines)
print outputLines
client.close()
或者使用paramiko
import paramiko
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.load_system_host_keys()
client.connect(SERVER_HOSTNAME, port=SERVER_PORT, username=SERVER_USERNAME, password=SERVER_PASSWORD)
_,stdout,_ = client.exec_command("ls -lh --color", 10240)
outputLines = stdout.readlines()
outputLines = "".join(outputLines)
print outputLines
client.close()
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询