node.js - Cookie not accepted while web-scraping with NodeJS -
i'm making script web-scrape response post request in form. thing page asks cookie jsessionid on it, before that, script makes request same page rescue cookie sent use in post request, page response 'error 400: invalid path /salidaaplicacion requested'
var request = require('request'); var async = require('async'); request = request.defaults({ jar: true }); var url = "http://civil.poderjudicial.cl/civilporweb/atpublicodaction.do"; var headers = { 'host': 'civil.poderjudicial.cl', 'user-agent': 'mozilla/5.0 (x11; ubuntu; linux x86_64; rv:44.0) gecko/20100101 firefox/44.0', 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'accept-language': 'en-us,en;q=0.5', 'accept-encoding': 'gzip, deflate', 'connection': 'keep-alive' } var options = { url: url, followredirect: true, forever: true, headers: headers } var form = { 'content-type': 'application/x-www-form-urlencoded', 'content-length': '326', 'tip_consulta': '3', 'tip_lengueta': 'tddos', 'seleccionl': '0', 'ruc_tribunal': '3', 'fec_desde': '01/1/2016', 'fec_hasta': '01/2/2016', 'sel_litigantes': '0', 'cod_tribunal': '375', 'iraccionatpublico': 'consulta', 'cpmonth': '1', 'cpyear': '2016' } var cookie; async.series([ function getcookie(callback) { request.get(options, function(error, response, body) { cookie = response.headers['set-cookie'][0]; callback(null, 1); }) }, function getpage(callback) { headers['cookie'] = cookie; request.post({ url: url, form: form, headers: headers }, function(err,httpresponse,body){ if (err) return console.error('error:', err); console.log(body); callback(null, 1); }); }] );
also, when using cookie web browser page responds in expected way, apparently cookie rescued not accepted page. in advance!
Comments
Post a Comment