selserver.py 882 B

123456789101112131415161718192021222324252627282930313233
  1. import sys
  2. import json
  3. sys.path.insert(0,'./kw_tools/web')
  4. import browser_common
  5. import rpyc
  6. from rpyc.utils.server import ThreadedServer # or ForkingServer
  7. class MyService(rpyc.Service):
  8. def __init__(self):
  9. self.jb=browser_common.JBrowser()
  10. #jb.set_profile_path('/home/jared/.config/google-chrome/Default/')
  11. self.jb.set_profile_path('"/home/jared/.config/google-chrome/"')
  12. def exposed_get_url(self,url):
  13. self.jb.get(url)
  14. driver=self.jb.get_driver()
  15. src=driver.page_source
  16. return json.loads(driver.find_element_by_tag_name('body').text)
  17. # return src
  18. def exposed_get_driver(self):
  19. return self.jb.get_driver()
  20. # print(src)
  21. #'https://data.similarweb.com/api/v1/data?domain=yahoo.com.tw'
  22. if __name__ == "__main__":
  23. server = ThreadedServer(MyService, port = 12345)
  24. server.start()