作者illl (ill!)
看板Ajax
标题[问题] node用request登入
时间Wed Apr 6 07:20:55 2016
https://www.discogs.com/login?nologin=1&return=%2Fsell%2Fhistory%2F1985784%3F
我想用request(这个
https://github.com/request/request) 登入这个网页
(登入form的action也是这个网址)
这是我用的code:
request.post({
uri:
"
https://www.discogs.com/login?nologin=1&return=%2Fsell%2Fhistory%2F1985784%3F",
form: {username: "xxxx", password: "yyyy"}
}, function (err, res, body) {
if (err) console.log(err);
console.log(body);
});
不过body还是一样的页面
我希望能得到登入後的页面
https://www.discogs.com/sell/history/1985784
请问我那里弄错了?
谢谢
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 108.0.72.181
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Ajax/M.1459898462.A.922.html
1F:推 johnny9144: 我想可能是你node的 sessions 机制没打开 预设是不启 04/06 18:43
2F:→ johnny9144: 用,所以你登入後 还是没有伺服器要的session-cookies 04/06 18:43
3F:→ johnny9144: 可以存取 你多宣告一个 var j = request.jar()试试 04/06 18:43
4F:→ johnny9144: 看 04/06 18:43
5F:→ johnny9144: 然後还有这句 request = request.defaults({jar:j}); 04/06 18:46
6F:→ johnny9144: 刚忘了 ,这样登入的session-cookies 才会被记得 04/06 18:46
7F:→ johnny9144: 如果还是不行 就要观察你form 送出的东西 跟他登入的 04/06 18:49
8F:→ johnny9144: 时候送出的 name 是不是一样 04/06 18:49
9F:→ illl: 感谢回覆 04/07 12:08