我正在编写从另一个站点检索网页的 JavaScript,并且只显示来自站点的“通知”。
幸运的是,所有“通知”都是“事件”类的 div 元素。
我只想从返回的代码中提取这些 div,以便我可以重新格式化并显示它们。到目前为止我所有的代码都在工作,但我不确定如何从源代码中提取“事件”div。有任何想法吗?
function getNotices(){
// Get the date from the form
var str = document.getElementById('formDate').value;
var year = str.slice(1,4); // Extract Year
var month = str.slice(6,7); // Extract Month
var day = str.slice(9,10); // Extract Day
// Inject correct date into URL
var link = "<a href=\"http://ilearn.stpauls.school.nz/calendar/view.php?view=day&course=1&cal_d=" + day + "&cal_m=" + month + "&cal_y=" + year + "\">Raw Link</a>";
// Write raw link to div for debugging
document.getElementById('rawLink').innerHTML = link; (debugging)
// Bounce off anyorigin.com to get the source
// Re-inject date into new link
var anyLink = "http://anyorigin.com/get?url=http%3A//ilearn.stpauls.school.nz/calendar/view.php%3Fview%3Dday%26course%3D%26cal_d%3D" + day + "%26cal_m%3D" + month + "%26cal_y%3D" + year + "&callback=?"; // Splice the date into the school link and site to bounce it off
$.getJSON('http://anyorigin.com/get?url=http%3A//ilearn.stpauls.school.nz/calendar/view.php%3Fview%3Dday%26course%3D1%26cal_d%3D30%26cal_m%3D7%26cal_y%3D2013&callback=?', function(data){
var obj = JSON.stringify(data); // Turn object into a string
document.getElementById('hopefullyTheData').innerHTML = obj; // Print string containing SPC website onto page (debugging)
});
}
多谢你们!