#coding =utf-8
‘‘‘
Created on 2017-9-9
@author: Ceshi from https://testerhome.com/topics/9897
‘‘‘
# rpcserver.py
Import Pickle
From Selenium.webdriver.chrome.webdriver import Webdriver
From multiprocessing.connection import Listener
From threading Import Thread
Dr = Webdriver (executable_path= "D:\\python27\\chromedriver")
def rpc_server (Handler, address, Authkey):
Sock = Listener (address, Authkey=authkey)
While True:
Client = Sock.accept ()
t = Thread (target=handler.handle_connection, args= (client,))
T.daemon = True
T.start ()
Class Rpchandler (object):
def __init__ (self):
# RPC Functions Map
Self._functions = {}
def register_function (Self, func):
SELF._FUNCTIONS[FUNC.__NAME__] = Func
def handle_connection (self, Connection):
Try
While True:
#接收到一条消息, using Pickle Protocol encoding
Func_name, args, Kwargs = Pickle.loads (Connection.recv ())
# RPC calls the function and returns the result
Try
r = Self._functions[func_name] (*args, **kwargs)
Print (Type (r))
Connection.send (Pickle.dumps (R))
Except Exception as E:
Connection.send (Pickle.dumps (e))
Except Eoferror:
Pass
if __name__ = = ' __main__ ':
# Write a few test methods
def add ():
Reload (rpcclient)
Rpcclient.get (DR)
# Create a new instance of the handler class and register the Add method with the handler
Import Rpcclient
From IMP import reload
Rpc_handler = Rpchandler ()
Rpc_handler.register_function (ADD)
Rpc_server (Rpc_handler, (' 192.168.3.19 ', 17001), authkey=b ' Tab_space ')
==========================
#coding =utf-8
‘‘‘
Created on 2017-9-9
@author: Ceshi
‘‘‘
#rpcclient. py
Import Pickle
Class RpcProxy (object):
def __init__ (self, Connection):
Self._connection = Connection
def __getattr__ (self, name):
# by name, get a function
def do_rpc (*args, **kwargs):
Self._connection.send (Pickle.dumps ((name, args, Kwargs))
result = Pickle.loads (Self._connection.recv ())
If isinstance (result, Exception):
Raise result
return result
Return DO_RPC
def get (DR):
#dr. Get ("https://www.baidu.com")
Dr.get (' https://testerhome.com/topics/9897 ')
# Dr.get ("https://www.baidu.com")
# dr.find_element_by_id ("kw"). Send_keys ("Selenium")
# dr.find_element_by_id ("su"). Click ()
# Remote Connection and call
if __name__ = = ' __main__ ':
From multiprocessing.connection import Client
rpc_client = Client ((' 192.168.3.19 ', 17001), authkey=b ' Tab_space ')
Proxy = RpcProxy (rpc_client)
b = Proxy.add ()
Python selenium2 dynamic debugging