zhaobinglong / myBlog

https://zhaobinglong.github.io/myBlog/
MIT License
7 stars 0 forks source link

【记录】nodejs爬虫查询全国大学生四六级考试成绩 #147

Open zhaobinglong opened 3 years ago

zhaobinglong commented 3 years ago

奇怪的验证码

网站先用一个带有时间戳的url获取验证码,然后又在响应头里面重定向到最终的图片url地址,优秀! image

zhaobinglong commented 3 years ago

获取全部考试类型的key

image

zhaobinglong commented 3 years ago

劫持cookie

传统利用验证码的网站,更新验证码的时候,它一定要重新设置cookie,所以就看响应头,一定会看到set-cookie

image

zhaobinglong commented 3 years ago

通过验证码获取cookie

直接拼接验证码的url去劫持验证码图片,对方网站直接40,必须增加请求头相关的信息 image

注意看请求头 image

添加请求头,一举拿下

        const radom = Math.random()
    let path = 'http://appquery.neea.edu.cn/api/verify/get?t=' + radom
    var options = {uri: path, headers: {
        Host: 'appquery.neea.edu.cn',
        Referer: 'http://cjcx.neea.edu.cn/'
    }, maxRedirects:10};
    request(options, function (error, response, body) {

}
zhaobinglong commented 3 years ago

坑1: 302重定向导致cookie丢失

image

成功获取到对方网站的cookie和验证码图片url

router.get('/getCode', function(req, res, next) {
    const radom = Math.random()
    let path = 'http://appquery.neea.edu.cn/api/verify/get?t=' + radom  // 拼接出来验证码的链接
    superagent
    .get(path)
    .redirects(0)
    .set('Host', 'appquery.neea.edu.cn')
    .set('Referer', 'http://cjcx.neea.edu.cn/')
    .end((err, data) => {
        res.send(data.header)
    });
});
zhaobinglong commented 3 years ago

成功拿到数据

image