【问题标题】:enable cookies in Phantomjs + selenium在 Phantomjs + selenium 中启用 cookie
【发布时间】:2015-07-16 07:53:29
【问题描述】:

我想在我的armv7板上登录amazons3(使用url:'https://console.aws.amazon.com/iam/home?#security_credential')。我使用了here的phantom2.0.1和selenium2.45.0。

我可以成功打开网站,但是当我在填写用户名和密码后“提交”时,网站跳转到显​​示“请启用 Cookie 以继续”的错误页面。所以我想知道如何在 selenium 中为 phantomjs 启用 cookie。在我的 ubuntu12.04 中使用合适版本的 phantomjs,我可以成功

我的部分代码如下:

def __init__(self,username,password,login_url,width=1151,height=629):
    self.username = username
    self.password = password
    self.login_url = login_url
    dcap = dict(DesiredCapabilities.PHANTOMJS)  
    dcap["phantomjs.page.settings.userAgent"] = ( "Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) Phantomjs/2.0.1 Safari/534.34" )  
    self.driver = webdriver.PhantomJS(executable_path='/bin/phantomjs',desired_capabilities=dcap,service_args=['--ssl-protocol=any','--ignore-ssl-errors=true'])
    self.driver.set_window_size(width,height)

def _login_system(self):
    try:
        self.driver.get(self.login_url)
        print self.driver.page_source#I can success here
        WebDriverWait(self.driver, 30).until(lambda driver : self.driver.find_element_by_id("ap_email")).send_keys(self.username)
        WebDriverWait(self.driver, 30).until(lambda driver : self.driver.find_element_by_id("ap_password")).send_keys(self.password)
        WebDriverWait(self.driver, 30).until(lambda driver : self.driver.find_element_by_id("signInSubmit-input")).submit()#failed here and showing Please Enable Cookies to Continue

【问题讨论】:

  • PhantomJS 支持 cookie,它们默认是启用的。不确定,为什么这是一个问题。也许那个二进制文件不好。
  • @ArtjomB。感谢您的回答。我尝试在我的 armv7 板和 qemu 上使用 rootfs 编译 phantomjs,但它一直失败,我搜索了这个问题,有人提到了它可能内存不足。您对编译有什么建议吗?非常感谢.make[2]: *** [generated/JSDOMWindow.cpp] 错误 255 make[2]: 离开目录/phantomjs/src/qt/qtwebkit/Source/WebCore' make[1]: *** [sub-DerivedSources-pri-make_first-ordered] Error 2 make[1]: Leaving directory /phantomjs/src/qt/qtwebkit/Source/WebCore' make: *** [ sub-Source-WebCore-WebCore-pro-make_first-ordered] 错误 2

标签: python cookies selenium-webdriver phantomjs


【解决方案1】:

我找到了答案, 亚马逊似乎不接受用户代理中的“Phantomjs/(..*)”

失败:Mozilla/5.0(Macintosh;Intel Mac OS X)AppleWebKit/534.34(KHTML,如 Gecko)Phantomjs/2.0.1 Safari/534.34

OK:Mozilla/5.0(Macintosh;Intel Mac OS X 10.9;rv:36.0)Gecko/20100101 Firefox/36.0 WebKit

另外,我在useragent后面加了“WebKit”,因为“undefined is not an object”的问题(https://github.com/detro/ghostdriver/issues/325

还有,我遇到了“raise BadStatusLine(line)”的问题(比如这里:enter link description here)。可能是不匹配造成的 selenium 和 phantomjs 的版本,所以我改用 phantomjs1.9.8 (piksel/phantomjs-raspberrypi in github)

对于编译问题,如果要在arm板子上编译,最好使用swap来扩展内存。

【讨论】:

  • 感谢您解决此问题!也为我在亚马逊工作过。
猜你喜欢
  • 2016-04-20
  • 2017-07-16
  • 1970-01-01
  • 1970-01-01
  • 2021-09-01
  • 2016-06-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多