Request: 重定向后如何访问请求的 url?

创建于 2014-03-04  ·  3评论  ·  资料来源: request/request

我需要在重定向后访问请求的 URL,例如:

 function(err, resp,body){
            $ = cheerio.load(body);
            //console.log(jar.cookies);
            request.post({
                jar:jar,
                url:targetBaseURL+'/search.php?do=process',
                followAllRedirects: true,
                headers: {
                    'User-Agent': userAgent

                },
                form :{
                    's'             : '',
                    'do'            : 'process',
                    'searchthreadid': '0',
                    'query'         : '',
                    'titleonly'     : '0',

...
                proxy: 'http://127.0.0.1:8888'

            }, function(err, resp, body){
               console.log(resp.request.redirects); // array is empty
                $ = cheerio.load(body);
                $("[id*=post]").each(function(i, elem){

                    var title =$(elem).find('a strong');
                    if(!$(title).text().match(/livescores/i)) {
                        //console.log($(title).text().trim());
                        var post = $(elem).find('div > em');
                        //console.log($(post).text().trim());
                    }
                });

            })
        });

最有用的评论

这给了我我需要的东西 console.log(resp.request.uri.href);

在这里找到 - http://stackoverflow.com/questions/16687618/how-do-i-get-the-redirected-url-from-the-nodejs-request-module

所有3条评论

查看 response.request.redirects,它有一个重定向 url 数组。

@spollack谢谢。 不幸的是,它是一个空数组。

这给了我我需要的东西 console.log(resp.request.uri.href);

在这里找到 - http://stackoverflow.com/questions/16687618/how-do-i-get-the-redirected-url-from-the-nodejs-request-module

此页面是否有帮助?
0 / 5 - 0 等级