我想登录amazons3(网址:'https://console.aws.amazon.com/iam/home?#security_credential https://console.aws.amazon.com/iam/home?#security_credential')在我的armv7板上。我使用了phantom2.0.1here https://github.com/spfaffly/phantomjs-linux-armv6l和selenium2.45.0。
我可以成功打开网站,但是当我在填写用户名和密码后执行“提交”时,网站跳转到一个错误页面,显示“请启用 Cookies 以继续”。所以我想知道如何在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/(..*)”在用户代理中
失败:Mozilla/5.0(Macintosh;Intel Mac OS X)AppleWebKit/534.34(KHTML,如 Gecko)Phantomjs/2.0.1 Safari/534.34
正常:Mozilla/5.0(Macintosh;Intel Mac OS X 10.9;rv:36.0)Gecko/20100101 Firefox/36.0 WebKit
另外,我在用户代理的末尾添加了“WebKit”,因为“未定义不是对象”的问题(https://github.com/detro/ghostdriver/issues/325 https://github.com/detro/ghostdriver/issues/325)
更重要的是,我遇到了“raise BadStatusLine(line)”的问题(如下所示:在此输入链接描述 http://code.google.com/p/selenium/issues/detail?id=6690).也可能是不匹配造成的
selenium 和 phantomjs 的版本不同,所以我使用 phantomjs1.9.8 代替(github 中的piksel/phantomjs-raspberrypi)
对于编译问题,如果要在arm板上编译,最好使用swap来扩展RAM。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)