我正在使用cheerios来搜索_csrf
并表达发布帖子请求:
request('http://scdownloader.net/', function (error, response, html) {
if (!error && response.statusCode == 200) {
var $ = cheerio.load(html);
var form = $("#mainForm");
var _csrf;
// Scrape for _csrf
for (var i = 0; i < form[0].children.length; i++) {
var a = form[0].children[i].attribs
if (a != null) {
a = a.class
if (a != null && a === "large-5 columns btn-wrapper") {
a = form[0].children[i].children;
for (var i = 0; i < a.length; i++) {
var b = a[i].attribs;
if (b != null) {
if (b.name != null && b.name === '_csrf') {
_csrf = b.value;
console.log(_csrf);
}
}
}
}
}
if (_csrf == null) {
// Callback with error
}
var title = "/newpartyarmy/tell-me-the-truth";
var url = "https://soundcloud.com" + title;
var form = {
_csrf: _csrf,
url : url
}
request.post({url:'http://scdownloader.net/download', form: form}, function(err, httpResponse, body){
if (!err && httpResponse.statusCode == 200) {
console.log(body);
console.log(httpResponse);
}
console.log(httpResponse.statusCode);
console.log(httpResponse.statusMessage);
})
}
});
这会返回403
状态代码。但是,当我转到scdownload.net
自己获取_csrf
并使用http://http-post.com/进行发布时,它可以正常运行。但是,对于我的废弃版本,它不起作用。
示例报废版本:Ii055I/uIr/44xbG3cB/1581eCjKEY/A9yR6XY88JGg=
示例手动废弃版本:m2RRexmzE3La1pD168ONDlz0giZlBdoxlUeyaJpBIeE=
答案 0 :(得分:1)
在我看来,该网站需要使用cookies。根据要求使用jar: true
。
实施例:
var request = request.defaults({jar: true})
request('http://www.google.com', function () {
request('http://images.google.com')
})