3

I am trying to pass certain ip's through customHeader in phantomJS, to show various rating logos based on ip. The first time i set the header to a specific ip the page reflects the ip (correct image loads). When i then try to modify the customHeader and then load another page, the page reflects the old ip.

#loop through passing different ip's
    if self.phantom is not None:
        #These seem to do nothing to fix the issue
        #self.phantom.get('javascript:localStorage.clear();')
        #self.phantom.delete_all_cookies()
        self.phantom.close()
        self.phantom.quit()
        self.phantom = None

    service = ['--ignore-ssl-errors=true', '--disk-cache=false']
    dcaps = {'handlesAlerts': True, 'javascriptEnabled': True}
    dcaps['phantomjs.page.settings.userAgent'] = (
            "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/53 "
            "(KHTML, like Gecko) Chrome/15.0.87")

    #No matter if i set customHeader during creation or after i get same result
    #if custom_header_name is not None and custom_header_value is not None:
    #    dcaps['phantomjs.page.customHeaders.{0}'.format(custom_header_name)]=custom_header_value

    self.phantom = webdriver.PhantomJS(executable_path=self.config.settings['phantom_js_dir'], desired_capabilities=dcaps, service_args=service)

    self.phantom.desired_capabilities[u'phantomjs.page.customHeaders.{0}'.format(custom_header_name)] = custom_header_value

    self.phantom.get(self.url)
    self.phantom.save_screenshot("C:\\test.png")

I have tried to clear cookies, cache and resetting the customHeader, but ONLY the first ip rating logo renders even though when i watch the customHeader value it changes (to correct values) throughout the run.

UPDATE: http://pastebin.com/uAm4Sk3R (More in depth code)

Darthlemi
  • 173
  • 1
  • 1
  • 9

0 Answers0