0

So there is a website that I must visit several times during different times of the day, to collect some basic information, the more times I visit it, the better. Some days I visit it as many as 20 times.

Let say this information is a number that is stored in a div, on a remote site, as follows:

<div class="importantInfo">24</div>

Assume, this HTML exists on some remote website with the following domain: http://www.somedomain.com.

Is it possible to create and execute JavaScript script on my local machine that navigates to http://www.somedomain.com and listen for an events on some remote website and acts accordingly on my local machine?

Something like (local JavaScript code):

var goTo = href('http://www.somedomain.com');

var num = goTo.('.importantInfo').text();

if(num > 10){
    alert("GOOD");
}

I appreciate any suggestions.

Many thanks in advance!

AnchovyLegend
  • 12,139
  • 38
  • 147
  • 231
  • have you tried using an iframe for the domain you are wanting to check and then using jquery to traverse the dom in the iframe and find your value? Checkout this link: http://stackoverflow.com/questions/6316979/selecting-an-element-in-iframe-jquery – JanR Jun 18 '13 at 03:01
  • What do you mean by "an event on a remote website"? Websites are just data, there are no events. Are you expecting to be notified when that 24 changes to something else? – Barmar Jun 18 '13 at 03:01
  • @Bamar, I apologize, see edited title. I meant, is there a way to navigate to and know what *data* is on some outside website and create JS events on my local machine based on this *data* on an outside site? – AnchovyLegend Jun 18 '13 at 03:04
  • Maybe you're looking for a headless browser? See http://phantomjs.org/ – bfavaretto Jun 18 '13 at 03:11
  • they should provide some web service ,otherwise you shouldn't be taking that info – Arun Killu Jun 18 '13 at 03:20
  • you can simply use greasemonkey or tampermonkey to run your own code on the site and send it home using url hash to localStorage or downloading a report file to the computer it's running on... you can also fetch it with YQL from any domain. – dandavis Jun 18 '13 at 04:09

1 Answers1

0

In short: no, you can't do this. If you load a web page from your local machine or a web server, your Javascript can't then go to another server to get pages. This is a security restriction built in to all browsers. There is an exception if the third-party server is configured to handle CORS (Cross-origin Resource Sharing) requests, but this is not commonly supported yet.

If you have your own web server there's nothing to stop that server requesting the page from the 3rd party server, and then having your Javascript request it from your own server, however.

  • Thanks for the reply. Can you please reword your answer, it doesn't really make sense. I am trying to load a webpage from some remote server on my local machine using JavaScript, and creating events on my local machine based on this remote data. – AnchovyLegend Jun 18 '13 at 03:40
  • I changed the wording. Get back to me if it still makes no sense to you. –  Jun 18 '13 at 03:50