简体   繁体   中英

Pull content from another website

I'd like to pull pictures and / or videos from another website onto my page, and i'd like to edit the looks with css. The website ofc. has rss, but i don't have an idea of how to do this. Someone told be before that i could ping the website and if there is new content, it automatically displays it on my site. How can this be done?

Thanks!

I am not quite sure if this is directly possible as it could theoretically cause a lot of traffic for the third-party website. Maybe you can read the content in your RSS-Reader and use this to update your site indirectly.

After all, aren't we talking about stealing content?

As the Rss feed is XML, the best way to do this is with Ajax, here is a sample

window.onload = initAll;
var xhr = false;
var dataArray = new Array();
var url = "otherSites.xml";

function initAll() {

if (window.XMLHttpRequest) {
    xhr = new XMLHttpRequest();
}
else {
    if (window.ActiveXObject) {
        try {
            xhr = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e) { }
    }
}

if (xhr) {
    xhr.onreadystatechange = setDataArray;
    xhr.open("GET", url, true);
    xhr.send(null);
}
else {
    alert("couldn't create XMLHttpRequest");
}
}

function setDataArray() {
var tag1 = "subject1";
var tag2 = "subject2";

if (xhr.readyState == 4) {
    if (xhr.status == 200) {
        if (xhr.responseXML) {

            var allData = xhr.responseXML.getElementsByTagName(tag1);
            for (var i=0; i<allData.length; i++) {
                dataArray[i] = allData[i].getElementsByTagName(tag2)[0].firstChild.nodeValue;
            }
        }
    }
    else {
        alert("the request failed" + xhr.status);
    }
}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM