在 Phantomjs + selenium 中启用 cookie

enable cookies in Phantomjs + selenium

我想登录 amazons3(使用 url:'https://console.aws.amazon.com/iam/home?#security_credential') on my armv7 board.I used phantom2.0.1 from here 和 selenium2.45.0.

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

我的部分代码如下:

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

我找到了答案, 好像amazon在useragent

里不接受"Phantomjs/(..*)"

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

确定:Mozilla/5.0 (Macintosh;英特尔 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),可能是dismatch导致的 selenium和phantomjs的版本,所以我改用phantomjs1.9.8(piksel/phantomjs-raspberrypi in github)

关于编译的问题,如果是在arm board上编译,最好使用swap来扩展RAM。