2

can anyone guide me how to simulate button click with cheerio?

the button is an image button. after click how to handle the __dopostback?

THANKS

Edit: i am trying the following code

process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0'; // Ignore 'UNABLE_TO_VERIFY_LEAF_SIGNATURE' authorization error

var request = require('request');
var cheerio = require('cheerio');

function postback(url, callback) {
    request.get(url, function onResponse(err, res, body) {

         $ = cheerio.load(body);

        var button = callback(err, $);

                if (button) {
            var form = {
                            __EVENTTARGET: button.attr('Button1'),
                __VIEWSTATE: $('#__VIEWSTATE').val(),
                __EVENTVALIDATION: $('#__EVENTVALIDATION').val(),
                __EVENTARGUMENT: $('__EVENTARGUMENT').val(),
                user:'username',
                pass: 'pasword',

            };

            request.post(url,  {form: form }, onResponse);

        }
    });
}


postback('https://mysite.com', function(err, $) {
 var button=$('input[type="image"]');
return button


})
user3904514
  • 71
  • 1
  • 4
  • Welcome to Stack Overflow. What does ```__dopostback``` mean? How does your code look like? What did you try so far ? (BTW: you should be able to find your answer by Googling for "site:stackoverflow.com node.js cheerio basics ```phantomjs```") – xmojmr Aug 18 '14 at 16:03
  • I'm trying to figure this out too -- I don't think Cheerio has a click method. My current plan of attack is save the url and create a new request outside of the current one. Hope that helps! – Kyle Chadha Nov 06 '14 at 03:06
  • Cheerio can't do this sort of thing. It's a simple HTML parser, not a browser automation library. – ggorlen Nov 26 '22 at 01:34
  • Does this answer your question? [How to fix '$(...).click is not a function' in Node/Cheerio](https://stackoverflow.com/questions/56675374/how-to-fix-click-is-not-a-function-in-node-cheerio) – ggorlen Jan 04 '23 at 19:24

0 Answers0