Last active
July 6, 2022 20:45
-
-
Save erfg12/2225545db3651d0f262190cb8c5651c4 to your computer and use it in GitHub Desktop.
RSS --> JS (CORS bypass)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<body> | |
<!-- host this on GitHub.com pages for free --> | |
<div id="DisplayData"></div> | |
<script> | |
fetch('https://cnet-rss-cors.herokuapp.com/') | |
.then(response => response.text()) | |
.then(data => { | |
parser = new DOMParser(); | |
xmlDoc = parser.parseFromString(data, "text/xml"); | |
Array.from(xmlDoc.getElementsByTagName("item")).forEach(element => { | |
document.getElementById("DisplayData").innerHTML += "<p><a href=\"" + element.getElementsByTagName("link")[0].innerHTML + "\"><img src=\"" + element.getElementsByTagName("media:thumbnail")[0].getAttribute('url') + "\"/><br><h3>" + element.getElementsByTagName("title")[0].innerHTML + "</h3>" + element.getElementsByTagName("description")[0].innerHTML + "</p>"; | |
console.log(element); | |
}); | |
}); | |
</script> | |
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// host this on Heroku.com for free | |
libxml_use_internal_errors(true); | |
header("Access-Control-Allow-Origin: *"); | |
header("Content-Type: application/xml; charset=UTF-8"); | |
error_reporting(E_ALL); | |
function GetURLData($url) { | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
$head = curl_exec($ch); | |
curl_close($ch); | |
return $head; | |
} | |
print_r(GetURLData("https://www.cnet.com/rss/news/")); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you want to do this for free, host the PHP script on Heroku and plug the URL into the client file. If you wanna host the JavaScript client somewhere for free, you can always use GitHub pages.
Want a list of great RSS feeds? Check this out! https://about.fb.com/wp-content/uploads/2016/05/rss-urls-1.pdf