Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1 

2import urllib.parse 

3from selenium import webdriver 

4from . import Base 

5 

6 

7class Phantom(Base): 

8 def boot_driver(self): 

9 self.log.debug("phantom args: %s", self.browser_args) 

10 return webdriver.PhantomJS(**self.browser_args) 

11 

12 def printpdf(self, output_fn): 

13 page_format = 'this.paperSize = {format: "A4", orientation: "portrait" };' 

14 self.execute(page_format, []) 

15 render = '''this.render("{}")'''.format(output_fn) 

16 self.execute(render, []) 

17 

18 def do_config(self, param): 

19 """ 

20 - name: config phantomjs 

21 config: 

22 cookie_flag: false 

23 proxy: 

24 url: http://proxy.host:8080/ 

25 - name: config common 

26 config: 

27 wait: 10 

28 cookie: 

29 var1: val1 

30 window: 

31 width: 600 

32 height: 480 

33 """ 

34 super().do_config(param) 

35 if "cookie_flag" in param: 

36 if param.get("cookie_flag", True): 

37 self.execute("phantom.cookiesEnabled=true") 

38 else: 

39 self.execute("phantom.cookiesEnabled=false") 

40 if "proxy" in param: 

41 prox = param.get("proxy") 

42 host = prox.get("host") 

43 port = prox.get("port", 8080) 

44 ptype = prox.get("type", "http") 

45 username = prox.get("username") 

46 password = prox.get("password") 

47 with_page = prox.get("page", False) 

48 url = prox.get("url") 

49 if url is not None: 

50 u = urllib.parse.urlparse(url) 

51 if u.scheme in ("", b""): 

52 self.log.debug("proxy not set. pass") 

53 return 

54 proxyscript = '''setProxy("{}", {}, "{}", "{}", "{}")'''.format( 

55 u.hostname, u.port, ptype, u.username, u.password) 

56 elif host is None: 

57 proxyscript = '''setProxy("")''' 

58 elif username is not None and password is not None: 

59 proxyscript = '''setProxy("{}", {}, "{}", "{}", "{}")'''.format( 

60 host, port, ptype, username, password) 

61 else: 

62 proxyscript = '''setProxy("{}", {}, "{}")'''.format( 

63 host, port, ptype) 

64 if with_page: 

65 prefix = "page" 

66 else: 

67 prefix = "phantom" 

68 self.execute(prefix + "." + proxyscript, [])