I am working on nodejs for scrapping a website and I am very new to nodejs.The website initial page is a popup in which one has to select option from selectbox and submit only then later pages can be browsed.this has to be done for first time and then it will be stored as cookie for later use.
I am able to get html page of popup but I am not able to select option from selectbox and submit request.
Here is my Code
var express = require('express');
var request=require('request');
var cheerio=require('cheerio');
var j = request.jar();
//var cookie = request.cookie();
j.setCookie("city_id=1; path=/; domain=.bigbasket.com", 'http://bigbasket.com/', function(error, cookie) {
//console.log("error"+error.message);
console.log("cookie "+cookie);
});
var app=express();
app.get('/', function(req, res){
console.log("hi");
var sessionVal = req.session;
request({uri:'http://bigbasket.com/',
headers:{'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36' ,
'content-type':'application/x-www-form-urlencoded; charset=UTF-8',
'connection':'keep-alive'},
jar:j},
function(err, response, body) {
// console.log("err "+err.message);
console.log("header"+JSON.stringify(response.headers));
console.log("status"+response.statusCode);
console.log("cookie "+response.cookie);
console.log(body);
var $=cheerio.load(body,{xmlMode: true});
console.log($);
var $selectBox= $('select').filter('.selectboxdiv');
console.log($selectBox.text());
response.end;
});
});
app.listen('8081')
console.log('Magic happens on port 8081');
exports = module.exports = app;
I am able to get select box options through below code :
var $selectBox= $('select').filter('.selectboxdiv');
console.log($selectBox.text());
But I am not able to select that option and submit.I have to select city from dropdown menu and submit request so that I could scrape data from upcoming webpages.
EDIT:
What do you see if you use 'req.body.NAME_OF_YOUR_DROPDOWN_HERE'? Maybe you can see the selected option then?