本帖最后由 wp231957 于 2020-3-17 16:02 编辑
反反爬题目二
题目说是主要考察cookie 实际上 也不知道都用了啥反扒措施,反正总是给我抛出302
const http=require("http");
//反反爬练习题二
//"http://www.porters.vip/verify/cookie/content.html"
// 构建options
var options={
hostname:"www.porters.vip",
port:80,
//这是一个重定向的路由
//重定向后是headers里的 "Referer"
//但是,如果你去请求"Referer"链,你会失望的
path:"/verify/cookie/content.html",
method:"GET",
//这个headers中 也不知道哪些是必须的,反正把F12中所有的都搬过来
//肯定是不行的,这些估计也有非必须的,懒得测试了
headers:{
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Accept-Language": "zh-CN,zh;q=0.9",
"Connection": "keep-alive",
"Cookie": "isfirst=789kq7uc1pp4c",
"Host": "www.porters.vip",
"Referer": "http://www.porters.vip/verify/cookie/index.html",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3947.100 Safari/537.36"
}
};
req=http.request(options,
res=>{
var str="";
res.on('data', buffer => {
str+=buffer;
});
res.on('end', () => {
console.log(str);
});
});
req.on('error', function (e) {
console.log('problem with request: ' + e.message);
});
req.end(); //结束请求,必须,否则会一直请求
|