2

ThE website http://www.uroulette.com/visit/owtqt redirects to random URLs. I would like to print 5000 of these random URLs to a document.

How do I do that? (I only know basic JavaScript, so I don't even know where to start with this task...).

The uroulette URL seem to change every hour or so (basically, the URL is just the link when clicking on the roulette pic on http://www.uroulette.com/).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Emilio
  • 1,314
  • 2
  • 15
  • 39
  • do they offer any kind of API ?? – JV Lobo Jul 04 '17 at 01:46
  • no, they don't; Just trying to do the same as OP here but in Javascript: https://stackoverflow.com/questions/20619746/how-do-i-go-to-a-random-website-python @JVLobo Is it possible to get the URL of a page without loading it in a browser? (such as this but from the outside): https://stackoverflow.com/questions/1034621/get-current-url-in-web-browser – Emilio Jul 04 '17 at 01:51
  • 1
    it's gonna be difficult, because if you go to that page from your JS code, you loose control because you're not gonna be on your page anymore, so... not sure if you can load that URL on an iframe and get the redirected URL, and then refresh the iframe and so on... but I'm not sure if that would work actually – JV Lobo Jul 04 '17 at 02:00
  • @JVLobo Uroulette seems not to allow iframes :/ https://codepen.io/aguyinmontreal/pen/KqRZGm – Emilio Jul 04 '17 at 02:13
  • or is it possible with NodeJS ? – Emilio Jul 04 '17 at 02:34

1 Answers1

1

To get random URLs, you can keep sending GET request to http://www.uroulette.com/visit/owtqt, and check the expected 302 response status code. If the response status code is 302, then the location response header contains the random URL.

Here is an example for collecting 10 random URLs in Node.js:

var http = require('http');

var urls = [];

var visitNum = 10;
function visitUroulette() {
  if (visitNum === 0) {
    console.log(urls);
    return;
  }

  visitNum--;

  console.log('Sending request...');
  http.get({
    hostname: 'www.uroulette.com',
    port: 80,
    path: '/visit/owtqt'
  }, function(res) {
    if (res.statusCode === 302) {
      urls.push(res.headers.location);
    }
    visitUroulette();
  });
}

visitUroulette();

Please note uroulette.com has some policy to protect site from data scrapping. In my local test, uroulette.com reset the HTTP connection if the visitNum in the above code exceeds 86. To get 5000 random URLs, you need to execute the program in various machine, various time.

shaochuancs
  • 15,342
  • 3
  • 54
  • 62