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
2010-01-30 01:55:03
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
2010-01-30 03:34:31
+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
2010-01-30 01:59:18
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
2010-01-30 03:28:52
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
2010-01-30 04:16:45
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
2010-02-01 03:34:39
I'm not sure why but as soon as I nested my test div inside another div it started to work.
Gekitsuu
2010-02-01 05:54:30