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 評価