Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6006831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:35:46+00:00 2026-05-23T01:35:46+00:00

I am using jsdom, jquery and node.js to scrape websites. Is there any way

  • 0

I am using jsdom, jquery and node.js to scrape websites. Is there any way I can post a form and get the resulting next page window using jsdom.

Here is the code

var httpAgent = require('http-agent'),
    jsdom = require('jsdom'),
    request = require('request');

request({uri:'http://www.orbitz.com'}, function(error, response, body){
  if(error && response.statusCode != 200)
    console.log('Error on request');

  jsdom.env({
    html: body,
      scripts : [
        'http://code.jquery.com/jquery-1.5.min.js'
      ]
    }, function(err, window) {
          var $ = window.jQuery;

          $('#airOneWay').attr('checked', true);
          $('#airRoundTrip').removeAttr('checked');
          $('#airOrigin').val('ATL');
          $('#airDestination').val('CHI');

          // here we need to submit the form $('#airbotForm') and get the resulting window
          //console.log($('#airbotForm').html());
   });
});

This is the form which needs to be submitted $('#airbotForm') and the resulting page has to be captured.

Can anybody help?
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:35:47+00:00Added an answer on May 23, 2026 at 1:35 am

    Oh man. This is where we get into crazy land.

    As it stands, the key difference between jsdom and “the browser” is we can access the window externally. For instance in your example you set $ to window.$, which is basically saying “hey, for this current window I want a reference to the jquery object”. You could have 10’s of windows, and hold references to all of their $‘s.

    Now, lets say you load a new page due to a form submission/link click…

    JSDOM would need to reload the window and update the javascript context (potentially injecting the scripts you provided in the original jsdom.env call). Unfortunately, the reference(s) you held from the last window would be gone/overwritten. In other words, calling $(...) after the page had reloaded would result in unexpected behavior (most likely a memory leak or selection of dom elements on the previous page)

    How do you get around this?

    Since you are using jquery already, do something like..

    var form   = $('#htlbotForm');
    var data   = form.serialize();
    var url    = form.attr('action') || 'get';
    var type   = form.attr('enctype') || 'application/x-www-form-urlencoded';
    var method = form.attr('method');
    
    request({
      url    : url,
      method : method.toUpperCase(),
      body   : data,
      headers : {
        'Content-type' : type
      }
    },function(error, response, body) {
      // this assumes no error for brevity.
      var newDoc = jsdom.env(body, [/* scripts */], function(errors, window) {
        // do your post processing
      });
    });
    

    YMMV, but this approach should work in non-ajax situations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Node.js noob. I am using node.io to scrape websites but I would love to
I'm using jQuery with jsdom (0.2.10). For some reason node.exe (0.6.5.1) never returns when
I'm using jQuery with jsdom in my node.js app. Moreover, I want to use
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters
In Node.js , other than using child process to make CURL call, is there
When using the JSDOM module on raw html, it removes any trace of inline
I am trying to scrape some information of a page using the jsdom.env function.
I did require('jsdom') in node js but i constantly get jsdom module not found.
how can i made this comment's properly using jsdoc. Any ideas??? /********************** * @variables

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.