var request = require('request');
var cheerio = require('cheerio');
var FormData = require('form-data');
var formTemplate = require('./form');


formData = formTemplate.getForm();

// customize form data
formData['ICAction'] = 'CLASS_SRCH_WRK2_SSR_PB_CLASS_SRCH';
formData['CLASS_SRCH_WRK2_INSTITUTION$42$'] = 'QNS01';
formData['CLASS_SRCH_WRK2_STRM$45$'] = '1162';
formData['SSR_CLSRCH_WRK_SUBJECT_SRCH$0'] = 'CSCI';


var options = {
    url: 'https://hrsa.cunyfirst.cuny.edu/psc/cnyhcprd/GUEST/HRMS/c/COMMUNITY_ACCESS.CLASS_SEARCH.GBL?PortalActualURL=https%3a%2f%2fhrsa.cunyfirst.cuny.edu%2fpsc%2fcnyhcprd%2fGUEST%2fHRMS%2fc%2fCOMMUNITY_ACCESS.CLASS_SEARCH.GBL&amp;PortalContentURL=https%3a%2f%2fhrsa.cunyfirst.cuny.edu%2fpsc%2fcnyhcprd%2fGUEST%2fHRMS%2fc%2fCOMMUNITY_ACCESS.CLASS_SEARCH.GBL&amp;PortalContentProvider=HRMS&amp;PortalCRefLabel=Class%20Search&amp;PortalRegistryName=GUEST&amp;PortalServletURI=https%3a%2f%2fhome.cunyfirst.cuny.edu%2fpsp%2fcnyepprd%2f&amp;PortalURI=https%3a%2f%2fhome.cunyfirst.cuny.edu%2fpsc%2fcnyepprd%2f&amp;PortalHostNode=ENTP&amp;NoCrumbs=yes',
   
    headers: {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36'
    },

    formData : formData, 

    jar: request.jar()
};

request.post(options, function(err, res, body) {
    /*if(err) {
        console.error(err);
        return;
    } else {
        console.log(res);
    }*/
    console.log(res.headers);
});
@@ -141,284 +141,30 @@
 );%0A%0A
-%0AformData = formTemplate.getForm();%0A%0A// customize form data%0AformData%5B'ICAction'%5D = 'CLASS_SRCH_WRK2_SSR_PB_CLASS_SRCH';%0AformData%5B'CLASS_SRCH_WRK2_INSTITUTION$42$'%5D = 'QNS01';%0AformData%5B'CLASS_SRCH_WRK2_STRM$45$'%5D = '1162';%0AformData%5B'SSR_CLSRCH_WRK_SUBJECT_SRCH$0'%5D = 'CSCI'
+jar = request.jar()
 ;%0A%0A
-%0A
 var 
@@ -827,12 +827,8 @@
 s',%0A
-   %0A
     
@@ -837,25 +837,16 @@
 aders: %7B
-%0A        
 'User-Ag
@@ -966,43 +966,10 @@
 .36'
-%0A    %7D,%0A%0A    formData : formData, %0A
+%7D,
 %0A   
@@ -974,29 +974,19 @@
    jar: 
-request.
 jar
-()
 %0A%7D;%0A%0Areq
@@ -1039,10 +1039,8 @@
     
-/*
 if(e
@@ -1099,48 +1099,511 @@
   %7D 
-else %7B%0A        console.log(res);%0A    %7D*/
+%0A    %0A    var parsed = cheerio.load(body);%0A    var key = parsed('form%5Bname=%5C'win0%5C'%5D%3Einput%5Bname=%5C'ICSID%5C'%5D').val();%0A%0A    formData = formTemplate.getForm();%0A    formData%5B'ICSID'%5D = key;%0A    formData%5B'ICAction'%5D = 'CLASS_SRCH_WRK2_SSR_PB_CLASS_SRCH';%0A    formData%5B'CLASS_SRCH_WRK2_INSTITUTION$42$'%5D = 'QNS01';%0A    formData%5B'CLASS_SRCH_WRK2_STRM$45$'%5D = '1162';%0A    formData%5B'SSR_CLSRCH_WRK_SUBJECT_SRCH$0'%5D = 'CSCI';%0A    options%5BformData%5D = formData; %0A%7D);%0A%0Arequest.post(options, function(err, res, body) %7B
 %0A   
@@ -1619,19 +1619,12 @@
 log(
-res.headers
+body
 );%0A%7D

Modify bot structure