Guest User

Untitled

a guest
Feb 12th, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.34 KB | None | 0 0
  1. header_value_list = ["27.101.101.1", "186.192.18.98", "210.242.154.60"]
  2.  
  3. for header_vaule in header_value_list:
  4.     self.reinstantiate_phantom('X-Real-IP', header_value)
  5.     self.phantom.get(url_to_site)
  6.     self.phantom.save_screenshot('C:\\test.png') #View screenshot and it only shows the first icon in the loop
  7.  
  8. def reinstantiate_phantom(self, custom_header_name=None, custom_header_value=None):
  9.         if self.phantom is not None:
  10.             self.phantom.get('javascript:localStorage.clear();')
  11.             self.phantom.delete_all_cookies()
  12.             self.phantom.close()
  13.             self.phantom.quit()
  14.             self.phantom = None
  15.  
  16.         service = ['--ignore-ssl-errors=true', '--disk-cache=false']
  17.         dcaps = {'handlesAlerts': True, 'javascriptEnabled': True}
  18.         dcaps['phantomjs.page.settings.userAgent'] = (
  19.                 "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/53 "
  20.                 "(KHTML, like Gecko) Chrome/15.0.87")
  21.  
  22.         dcaps['phantomjs.page.settings.clearMemoryCaches'] = True
  23.  
  24.         if custom_header_name is not None and custom_header_value is not None:
  25.             dcaps['phantomjs.page.customHeaders.{0}'.format(custom_header_name)]=custom_header_value
  26.  
  27.         self.phantom = webdriver.PhantomJS(executable_path=self.config.settings['phantom_js_dir'], desired_capabilities=dcaps, service_args=service)
Add Comment
Please, Sign In to add comment