Python-PhantomJS customHeader更新未反映在网站上

时间:2016-02-12 19:15:14

标签: python phantomjs ghostdriver

我试图通过phantomJS中的customHeader传递某些ip,以显示基于ip的各种评级标识。我第一次将标头设置为特定的ip时,页面反映了ip(正确的图像加载)。当我然后尝试修改customHeader然后加载另一个页面时,该页面反映了旧的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")

我试图清除cookie,缓存和重置customHeader,但只有第一个ip rating徽标呈现,即使我在整个运行过程中观察customHeader值时它会改变(更正值)。

更新:http://pastebin.com/uAm4Sk3R(更深入的代码)

0 个答案:

没有答案