Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I access the url of the request after a redirect? #832

Closed
codecowboy opened this issue Mar 4, 2014 · 3 comments
Closed

How can I access the url of the request after a redirect? #832

codecowboy opened this issue Mar 4, 2014 · 3 comments

Comments

@codecowboy
Copy link

I need to access the url of a request after it has been redirected e.g:

 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());
                    }
                });

            })
        });
@spollack
Copy link
Contributor

spollack commented Mar 4, 2014

look in response.request.redirects, it has an array of the redirect urls.

@codecowboy
Copy link
Author

@spollack Thanks. Unfortunately, its an empty array.

@codecowboy
Copy link
Author

This gives me what I need console.log(resp.request.uri.href);

Found here - http://stackoverflow.com/questions/16687618/how-do-i-get-the-redirected-url-from-the-nodejs-request-module

@nylen nylen closed this as completed Aug 22, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants