比如,去抓一个需要登录的网站的资源时,首先模拟登录,获取cookie;然后在后续的请求中如何带着cookie?我查了API发现只有一个withCredentials()方法与cookie相关,但是试了一下不管用。
(来自https://manxisuo.github.io/)
试过 .set() 方法么?
.set()
var agent = new require('superagent').Agent() agent 会自动保存cookie 和 在请求中带上cookie agent.jar 可以先配置一些cookie 看下 cookieJar 的api 就知道了
var agent = new require('superagent').Agent()
agent.jar
cookieJar
@brickyang 把cookie保存下来,然后在后续每次请求时用: .set(‘cookie’, cookie) 是可以的,但是看起来太不优雅了。
@stormslowly 还可以这样?我看遍了文档(http://visionmedia.github.io/superagent/)没有找到.Agent()这个方法啊?
文档没有就看代码
https://github.com/visionmedia/superagent/blob/master/lib/node/agent.js#L27 https://github.com/visionmedia/superagent/blob/master/lib/node/agent.js#L74
https://github.com/alsotang/node-lessons/tree/master/lesson8请直接Ctrl+F搜 cookie 持久化
CNode 社区为国内最专业的 Node.js 开源技术社区,致力于 Node.js 的技术研究。
试过
.set()方法么?var agent = new require('superagent').Agent()agent 会自动保存cookie 和 在请求中带上cookieagent.jar可以先配置一些cookie 看下cookieJar的api 就知道了@brickyang 把cookie保存下来,然后在后续每次请求时用: .set(‘cookie’, cookie) 是可以的,但是看起来太不优雅了。
(来自https://manxisuo.github.io/)
@stormslowly 还可以这样?我看遍了文档(http://visionmedia.github.io/superagent/)没有找到.Agent()这个方法啊?
(来自https://manxisuo.github.io/)
文档没有就看代码
https://github.com/visionmedia/superagent/blob/master/lib/node/agent.js#L27 https://github.com/visionmedia/superagent/blob/master/lib/node/agent.js#L74
https://github.com/alsotang/node-lessons/tree/master/lesson8请直接Ctrl+F搜 cookie 持久化