0

How to wait for the page to load like say for 5 seconds.
In my program the sites wait for browser checks for 5 seconds before showing the content, Hence I want my http.get(url) function to wait for at least 5 seconds. Without wait it doesn't show any content.
Thanks.

user18233
  • 3
  • 2
  • What have you already tried ? Have you searched on google ? – darthShadow Mar 01 '17 at 12:16
  • yes, I have searched on google . There is "timeout" parameter but no "waitload" or "wait" parameter to wait for specified time.In Python selenium there is "waitload" so I'm searching for something like that. – user18233 Mar 01 '17 at 12:33

2 Answers2

0

Based upon your comments, I now understand what you are trying to do and have modified this answer.

Unfortunately, there is no way to configure Meteor HTTP (which really uses request to make the service call) to "wait" after the request has been initiated before obtaining a response. The best thing for you to do is to check out PhantomJS. It is a headless browser that you can use to load and render the page and then access dynamically generated content via javascript.

Check out this answer for a brief PhantomJS example and you can use the gadicohen:phantomjs package to install for meteor.

On a side note, it can still be useful to use the below function to pause execution in Meteor, but of course this is not useful for what you are trying to solve.

Meteor._sleepForMs(5000); // pause execution for 5 seconds
Community
  • 1
  • 1
jordanwillis
  • 10,449
  • 1
  • 37
  • 42
  • I want to scrape a site which at initial waits for 5 seconds to load the content, Initially it just shows "waiting for 5 seconds...". So what I want to do is to make http.get() call to wait for 5 seconds to load the content. – user18233 Mar 01 '17 at 18:33
  • @user18233 Thanks for the clarification. I have updated my answer to at least point you in the right direction for how to do this. – jordanwillis Mar 01 '17 at 19:16
0

the http package is built upon npm's request package. You can do it as such with the request package directly:

var request = require('request');
var reqOptions = {
    url: path,
    method: 'GET',
    encoding: "utf8",
    jar: false,
    timeout: null,
    body: null,
    followRedirect: null,
    followAllRedirects: null,
    headers: {},
    time:true
};
request(reqOptions, function(error, response, body) {
    console.log("time: "+response.elapsedTime)
    console.log(body.toString()); //res.content returned by http.get
});
require('sleep').sleep(5); //synchronously slowing execution

You might also be able to do the same by setting {time:true} in the npmOptions parameter of the http call and then synchronously

mutdmour
  • 543
  • 5
  • 14