bigdata/chapter1/crawler/client.py

40 lines
1.1 KiB
Python
Raw Normal View History

2019-01-15 16:07:01 +08:00
#!/usr/bin/env python
"""
Example script to control a Scrapy server using its JSON-RPC web service.
It only provides a reduced functionality as its main purpose is to illustrate
how to write a web service client. Feel free to improve or write you own.
Also, keep in mind that the JSON-RPC API is not stable. The recommended way for
controlling a Scrapy server is through the execution queue (see the "queue"
command).
"""
import telnetlib
def do_telnet(Host, finish):
'''Telnet远程登录Windows客户端连接Linux服务器'''
# 连接Telnet服务器
tn = telnetlib.Telnet(Host, port=6023, timeout=10)
tn.set_debuglevel(2)
# 输入登录用户名
out = tn.read_until(finish)
tn.write(b'est()\n')
print('-----------------1')
print(out.decode('utf8'))
print('-----------------11')
# 输入登录密码
out = tn.read_until(finish)
print('-----------------2')
print(out.decode('utf8'))
print('-----------------3')
tn.close() # tn.write('exit\n')
if __name__ == '__main__':
# 配置选项
Host = '127.0.0.1' # Telnet服务器IP
finish = b'>>> ' # 命令提示符
do_telnet(Host,finish)