我正在尝试使用节点js向某些链接(我不想在此处显示链接)发出http发布请求:
const form = {
'eid': 'xxx',
'pw': 'xxx',
'submit': 'Login'
};
function getCookie(callback) {
request({
url: "xxxxx",
form: form,
method: 'POST',
resolveWithFullResponse : true,
//followAllRedirects: true
//jar: true
}, function (loginErr, getCookieResponse,getCookieBody) {
if (loginErr)
console.log("Login Failed");
//callback(getCookieResponse);
//cookie = getCookieResponse.headers['set-cookie'];
/* SET COOKIE TO VISIT PAGES */
//request.jar(cookie);
// var j = request.jar();
let object = {
'User-Agent': 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
'Cookie': getCookieResponse.headers['set-cookie'][0],
//'host':'localhost:3000'
};
callback(object);
});
}
//console.log(headers);
function getLinksToVisit(headers, callback) {
let links_to_visit = [];
console.log(headers);
request({
url: "xxx",
headers: headers,
method: 'GET',
}, function (accessPage, getLinksResponse, getLinksHTML) {
var attributes = [];
console.log(getLinksHTML);
})
运行此代码段后,我能够以登录状态访问该网站,但未显示所有内容。在某些地方,我会看到一个方框,上面写着“请登录”,但其他一些内容也会显示出来。 我也尝试将请求从邮递员发送到该网站,邮递员也返回相同的结果。现在,我想从该网站上抓取一些数据,说请登录。