bigdata/chapter2/mysite/myapp/scrapy_client.py

48 lines
962 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#coding=utf-8
import telnetlib
import re
import pdb
import happybase
def get_crawl_data_info():
connection = happybase.Connection('106.75.85.84', port=40009)
table = connection.table('jd')
num = 0
for i in table.scan(scan_batching=True):
num += 1
return num
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')
# 输入登录密码
out = tn.read_until(finish)
tn.close() # tn.write('exit\n')
return out.decode('utf8')
def get_scrapy_info():
try:
response = do_telnet('127.0.0.1', b'>>> ')
mm = re.findall(r'(.+?)\s+?:\s+?(.+?)\s+', response)
info = {}
for m in mm:
info[m[0]] = m[1]
return info
except:
return {}
if __name__ == "__main__":
print(get_crawl_data_info())