-
-
Save clochix/8030179 to your computer and use it in GitHub Desktop.
Extract ATOM like informations from the home of a blog
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
var xhr = new XMLHttpRequest(); | |
xhr.onload = function (e) { | |
var doc = xhr.responseXML; | |
[].slice.call(doc.getItems('http://schema.org/Blog')).forEach(function(blog) { | |
var blogProps = blog.properties; | |
console.log("Blog name: " + blogProps["name"].getValues().join(',')); | |
console.log("Blog author: " + blogProps["author"].getValues().join(',')); | |
console.log("Blog url: " + blogProps["url"].getValues().join(',')); | |
[].slice.call(blogProps.blogPost).forEach(function (item) { | |
var itemProp = item.properties; | |
console.log("Post name: " + itemProp["name"].getValues().join(',')); | |
console.log("Post body: " + itemProp["articleBody"].getValues().join(',')); | |
console.log("Post date: " + itemProp["dateCreated"].getValues().join(',')); | |
console.log("Post name: " + itemProp["name"].getValues().join(',')); | |
console.log("Post author: " + itemProp["author"].getValues().join(',')); | |
}); | |
}); | |
} | |
xhr.onerror = function (e) { | |
}; | |
xhr.open('GET', "http://esquisses.clochix.net", true); | |
xhr.responseType = "document"; | |
xhr.send(); |
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
// Sample code to parse content of page http://www.academie-francaise.fr/dire-ne-pas-dire/neologismes-anglicismes | |
// Uses Green Turtle | |
// Include http://green-turtle.googlecode.com/files/RDFa.min.1.2.0.js | |
var subjects = document.data.graph.subjects; | |
Object.keys(subjects).forEach(function (subject) { | |
var predicates = subjects[subject].predicates, | |
content = subjects[subject].origins.reduce(function (prev, curr) { return prev + curr.innerHTML}, ''); | |
console.log(subject); | |
Object.keys(predicates).forEach(function (predicate) { | |
console.log(" → " + predicate + " → " + predicates[predicate].objects.reduce(function (prev, curr) { return prev + curr.value}, '')); | |
}) | |
console.log(content); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment