Request: Wie kann ich nach einer Weiterleitung auf die URL der Anfrage zugreifen?

Erstellt am 4. März 2014  ·  3Kommentare  ·  Quelle: request/request

Ich muss auf die URL einer Anfrage zugreifen, nachdem sie umgeleitet wurde, z.

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

            })
        });

Hilfreichster Kommentar

Das gibt mir, was ich brauche console.log(resp.request.uri.href);

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

Alle 3 Kommentare

Schauen Sie in response.request.redirects nach, es enthält ein Array der Umleitungs-URLs.

@spollack Danke. Leider ist es ein leeres Array.

Das gibt mir, was ich brauche console.log(resp.request.uri.href);

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

War diese Seite hilfreich?
0 / 5 - 0 Bewertungen

Verwandte Themen

pixarfilmz112 picture pixarfilmz112  ·  3Kommentare

lupo9557 picture lupo9557  ·  3Kommentare

jasonxia23 picture jasonxia23  ·  3Kommentare

ghost picture ghost  ·  3Kommentare

chenby picture chenby  ·  3Kommentare