phantomjs

How to configure Poltergeist or PhantomJS to not follow redirects?

吃可爱长大的小学妹 提交于 2019-12-04 01:40:58
问题 I have some tests that require the JS driver to not follow redirects. Is it possible to configure Poltergeist to do this? I noticed that it is possible to pass commands to PhantomJS using the Command Line Interface, so perhaps that is another way of doing this? 回答1: I'm not familiar with Poltergeist, so I'm only going to answer about PhantomJS. All you need for this are the two event handlers page.onResourceRequested and page.onResourceReceived. An HTTP redirect produces both a HTTP request

PhantomJS 1.8 with Selenium on python. How to block images?

人走茶凉 提交于 2019-12-04 01:12:47
Is there a way to configure PhantomJS webdriver on Selenium to do not load images? I know if I use phantomjs directly, I can start it with --load-images=no and it won't load the images, but how can I configure that via Selenium and Python? UPDATE Tried the following: args = { 'desired_capabilities': { 'loadImages': False } } driver = webdriver.PhantomJS(**args) No success... redice Why are you not trying webdriver.PhantomJS(service_args=['--load-images=no']) ? Pykler EDIT: passing arguments is exposed, see the same answer mentioned below for how to do it Passing arguments to phantomjs is not

Phantomjs append to file with fs.write

坚强是说给别人听的谎言 提交于 2019-12-03 23:32:25
How can I append to a file using fs.write() ? Using fs.write on the same files overwrites the content: var fs = require('fs'); try { fs.write("file.txt", "Hello World", 'w'); fs.write("file.txt", "Hello World", 'w'); } catch(e) { console.log(e); } Use append mode a instead of [over]write mode w in the fs.write call. var fs = require('fs'); try { fs.write("file.txt", "Hello World", 'a'); fs.write("file.txt", "Hello World", 'a'); } catch(e) { console.log(e); } I inferred this based on the python open() C fopen documentation; Glad it worked, other file modes may work but were not tested by me. 来源

Why is Capybara discarding my session after one event?

主宰稳场 提交于 2019-12-03 23:27:10
问题 Testing a rails application which has before_filter :authenticate_user! for most controllers, I cannot get Capybara to preserve a session. I have Capybara configured using PhantomJS with poltergeist. I use the following helper: require 'spec_helper' include Warden::Test::Helpers module FeatureHelpers def login(user = FactoryGirl.create(:default_user)) login_as user, scope: :user user end end I have the following spec file: require 'spec_helper' include Warden::Test::Helpers feature 'Leads

Firefox -> PhantomJs Login to website not working

99封情书 提交于 2019-12-03 21:55:40
For some reason when I don't run headless I am able to log into http://www.neighborhoodscout.com . However when I run headless PhantomJS I am unable to login and it can't find an element it returns on success of a login. Phantom JS version 1.9.8 driver = webdriver.PhantomJS() driver.set_window_size(1124, 850) driver.get(url) time.sleep(2) driver.find_element_by_id("login").click() time.sleep(2) driver.find_element_by_id("user_email").send_keys(username) driver.find_element_by_id("user_password").send_keys(password) time.sleep(4) driver.find_element_by_id("login-button").click() Why does it

Injecting & using Firebug-Lite with PhantomJS

冷暖自知 提交于 2019-12-03 21:51:36
I'm trying to inject Firebug & jQuery into a webpage using PhantomJS, but I'm unable to access them. I've tried both PhantomJS methods for adding other JS to a page: page.injectJs() and page.includeJs. I'm not able to get anything returned from includeJs (which I wasn't expecting to get, from reading the documentation). After I injectJs() and try to use firebug-lite and jQuery functions or objects (like $ and inspect() ) I get errors saying they are undefined or the variable can't be found. This is my complete script. You can also see it here: http://piratepad.net/XTPefXOB4o "use strict"; "use

利用Selenium和PhantomJS在Centos下跑测试

為{幸葍}努か 提交于 2019-12-03 21:14:25
做过selenium自动化项目的同学应该都遇到过这样的问题:测试用例太多,运行速度过慢导致团队成员怨声载道。 于是便有了selenium grid和多线程运行selenium测试用例的方法。这些方法各有利弊这里就不一一列举了。但总的来说,如果浏览器运行的速度足够快,那么多线程并发时的用例执行速度应该是可以满足实际项目需求的。 总结 踩的一些坑 1.字体。安装成功后,截图发现没有字体。 参考连接 http://www.easonhan.info/phantomjs/2015/01/10/ghost-driver/ http://www.lao8.org/article_1550/linux_centos_phantomjs http://phantomjs.org/build.html http://type.so/linux/phantomjs-chinese.html http://blog.csdn.net/wang1144/article/details/41746665 http://www.jhonge.net/Home/Single/26626627 来源: oschina 链接: https://my.oschina.net/u/199060/blog/488647

Selenium最新版本不再支持PhantomJS

天涯浪子 提交于 2019-12-03 21:13:52
Selenium最新版本不再支持PhantomJS 2018年09月19日 15:07:45 czbuyi 阅读数:600 今天想对《 自动读取单位某系统数据 》一文中的项目做些优化,将 Selenium + firefox 改为无界面的PhantomJS,出现如下错误: UserWarning: Selenium support for PhantomJS has been deprecated, please use headless versions of Chrome or Firefox instead warnings.warn('Selenium support for PhantomJS has been deprecated, please use headless ' 百度:意思是说Selenium不再支持PhantomJS,请用无界面版本的chrome或firefox代替。 完美解决方法转发自这个博客: Selenium+PhantomJS使用时报错原因及解决方案 在使用 webdriver 驱动器文件时,建议还是将其解压至某个目录,再手动指定 executable_path 参数,省得去设置环境参数(主要是因为我的mac里设置后总是不能用)。 使用无界面浏览器 Selenium+Headless Firefox Selenium+Headless

超详细的Python实现微博模拟登陆,小白都能懂

折月煮酒 提交于 2019-12-03 21:13:08
原文来自:公众号"速学Python" 前言 最近由于需要一直在研究微博的爬虫,第一步便是模拟登陆,从开始摸索到走通模拟登陆这条路其实还是挺艰难的,需要一定的经验,为了让朋友们以后少走点弯路,这里我把我的分析过程和代码都附上来。 首先,我们先用正常的账号登陆,具体看会有些什么请求。这里我用的是Http Analyzer抓包(Filders也是一个不错的选择)。下面是正常登陆流程的截图: 接下来我会详细说明各个过程。 第一步:预登陆。 现在微博、空间等大型网站在输入用户名后基本都会做编码或者加密处理,这里在用户名输入框输入我的账号,通过抓包工具可以看到服务器会返回一段字符串: 这一步就是预登陆过程,同学们可以自己试试。登陆的时候我们需要用到其中的servertime、nonce、pubkey等字段。当然这个不是我自己猜想的,后面的步骤会做说明。 还有一点,就是预登陆的url: 这里su的值是自己用户名经过base64编码的值。但可能你们会问我是如何知道的呢,待会儿我会讲到。经过实测,如果我们这里不给su传参数,其实也是可以的。为了最真实的模拟用户登录,我们最好还是带上它的值。 学习从来不是一个人的事情,要有个相互监督的伙伴,工作需要学习python或者有兴趣学习python的伙伴可以私信回复小编“学习” 获取资料,一起学习 请看图一的第一条js请求http://i.sso.sina

Login amazon using CasperJS with handling Captcha

岁酱吖の 提交于 2019-12-03 20:28:10
问题 I am using PhantomJs and CasperJs to login with amazon it works fine, however after multiple times login amazon gives Captcha and my script fails. I dont know how to handle login script if it has captcha. Here is my current code which works fine if no captcha. var casper = require('casper').create(); var AMAZON_USER = 'amazon-username'; var AMAZON_PASS = 'amazone-password'; casper.start('https://www.amazon.com/gp/wallet', function () { this.echo('Loggin into amazon...'); var emailInput =