lul*_*n21 4 python cookies phantomjs selenium-webdriver
我想在我的armv7板上登录amazons3(使用网址:' https : //console.aws.amazon.com/iam/home?#security_credential').我从这里使用了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
Run Code Online (Sandbox Code Playgroud)
我已经找到了答案,这似乎是亚马逊不接受"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不是对象"的问题(https://github.com/detro/ghostdriver/issues/325)
更重要的是,我遇到了"提高BadStatusLine(线)"的问题(就像这里:在这里输入链接描述).它可能是由于selenium和phantomjs版本的不匹配造成的,所以我使用phantomjs1.9.8代替(github中的piksel/phantomjs-raspberrypi)
对于编译问题,如果要在arm板上编译,最好使用swap来扩展RAM.
| 归档时间: |
|
| 查看次数: |
4606 次 |
| 最近记录: |