Comments (3)
did you figure out how to add a cookie ?
from node-phantom.
This issue should be clearly defined in some documentation somewhere because I have been trying for days to figure out how to successfully set cookies with phantomjs directly (script call from phantomjs), node-phantom, and phantomjs-node. It doesn't seem like any of the phantomjs-to-node modules are actively maintained at all.
from node-phantom.
@SgtPooki i figured it out later. indeed there should be more examples / documentation . fyi, it is ph.addCookie
example:
/**
* Created by KHAN on 1/28/2016.
*/
phantom.create(function (error, ph) {
ph.createPage(function (err, page) {
page.set('settings', {
userAgent: "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:40.0) Gecko/20100101 Firefox/40.0",
javascriptEnabled: true,
loadImages: false
});
phantom.cookiesEnabled = true;
phantom.javascriptEnabled = true;
steps = [
function () {
log.debug(site + 'Step 1 - Open login page : ' + loginPage);
page.open(loginPage, function (status) {
});
},
function () {
log.debug(site + 'Step 2 - Populate and submit the login form');
page.render('screenshots/xxxx/step-1-login-page.png');
var onLoginComplete = function (error, response, body, page, cookies) {
for (var i = 0; i < cookies.length; i++) {
if (cookies[i].key === authCookieName) {
log.info("Logged into xxxx , " + cookies[i].key + " is \n" + cookies[i].value);
ph.addCookie({
domain: 'xxxx.com',
expires: (new Date()).getTime() + (1000 * 60 * 60) /* <-- expires in 1 hour */,
httponly: true,
name: authCookieName,
path: '/',
secure: false,
value: cookies[i].value
});
}
}
loadInProgress = false;
};
page.get('cookies', function (err, cookies) {
for (var i = 0; i < cookies.length; i++) {
if (cookies[i].name === sessionCookieName && cookies[i].value.length > 0) {
loadInProgress = true;
myself.login(username, password, cookies[i].value, ph, onLoginComplete);
}
}
});
},
]
})
})
from node-phantom.
Related Issues (20)
- I want import a method execute in page.evaluate
- can page.render to stream HOT 1
- `phantom.create` fails with no trace or error
- phantom.create fails
- callback of page.render didn't work HOT 2
- first time execute ph.createPage , socket.io seems not prepared
- deploy our node with pm2 cluster mode . will it work well .
- createPage does not callback HOT 6
- meet phantom stdout: TypeError: undefined is not an object (evaluating 'phantom.args[0]') HOT 6
- pageOnError suppress errors
- pass quality parameter to render
- Wrong usage example
- Whitespace issue in the binary path
- page.includeJs hangs on https
- Add disclaimer: ABONDENED PROJECT HOT 4
- create page of undefined
- ssl error HOT 1
- ph is undefined HOT 1
- evaluate
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-phantom.