我正在尝试通过https://brilliant.org/account/login/进行身份验证, 但是,尽管我已发送了所有必需的表单数据,但未通过身份验证。可能是什么问题?
const checkIfAuthenticated = () => {
return new Promise(resolve => {
request.get('https://brilliant.org/notifications/get_updated_unread_count/', (err, res, body) => {
if (body === '{"logged_out": true}') {
return resolve('Login FAILED')
} else {
return resolve('Login SUCCESS')
}
})
})
}
/////////////////////////////////////////////////////////////////
const loginUrl = 'https://brilliant.org/account/login/'
var request = require('request');
var request = request.defaults({
jar: true,
headers: {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36"
}
});
const options = {
form: {
"login": 'bo@gmail.com',
"password": '12345',
"next": '/'
}
}
//////////////////////////////////////////////////////////////////
request.get(loginUrl, async (err, res, body) => {
const matches = await body.match(/csrfmiddlewaretoken' value='([a-zA-Z0-9]+)/m)
options.csrfmiddlewaretoken = matches[1]
request.post({url: loginUrl, options: options}, (err, res, body) =>
checkIfAuthenticated().then(loginStatus => console.log(loginStatus))
})
});
您可以自己尝试,请确保更改用户名和密码。