views:

64

answers:

2

Basically I'm trying to scrape a few divs out of several of the intranet sites at work. and include them on a page I run locally (so I can look at one page instead of having 5 open). I'm guessing this is possible with JavaScript but I'm primitive with JavaScript so I'm not sure what I need to search for to find the answers. After I scrape the Div's from these other pages I want to add a refresh timer with something like setInterval()

A: 

You can to access those external pages using an XMLHttpRequest object, grab it's HTML source and strip just that information you want.

maybe this link can be useful: Auto refresh <DIV> using ajax

Rubens Farias
Thanks I'm going to give this a try too and see which I like better. My gut tells me to avoid including jQuery just for this one task but I might end up needing it for other things in the future so I'm going to try that suggestion too
Gekitsuu
+2  A: 

This task is not as difficult as it should be, thanks to the glorious jQuery library...

$(document).ready(function() {
  // Repeat this for each of your URLs
  $.get("URL", function(data) {
    var resp = $(data); // Now you can do whatever you want with it
    $("#ID_OF_DIV", resp).appendTo("body");
  });
  // End Repeat

  setTimeout(function() {
    location.reload(true);
  }, 10000); // Refresh every ten seconds
});
Josh Stodola
the setTimeout seems to be causing the whole page to reload every 10 seconds, not sure why but thanks for the jQuery suggestion I'm trying this out. I'd upvote if I had enough rep yet
Gekitsuu
Causing the whole page to reload is what refreshes the content. If you want to do it differently, you can move this code to a different function and use `setInterval`. If you do this, dont forget to empty the body before appending new elements to it.
Josh Stodola
Awesome! thanks for the help :)
Gekitsuu
I just tried this out and I'm having some trouble getting it to work. I replaced "URL" with my test page and "#ID_OF_DIV" with "#Test" which is the id= of the div on the test page and nothing comes up. But if I remove "#ID_OF_DIV" from the 5th line the whole page shows as expected.
Gekitsuu
I'm not sure why but as soon as I nested my test div inside another div it started to work.
Gekitsuu