girl every day!
http://girlavday.blogspot.com/
// $X // based on: http://lowreal.net/blog/2007/11/17/1 // // $X(exp); // $X(exp, context); // $X(exp, type); // $X(exp, {context: context, // type: type, // namespace: {h:"http://www.w3.org/1999/xhtml"}}); function $X (exp, context) { var type, namespace={}; // console.log(String(exp)); if(typeof context == "function"){ type = context; context = null; }else if(typeof context != "undefined" && !context['nodeType']){ type = context['type']; namespace = context['namespace'] || context['ns']; context = context['context']; } if (!context) context = document; var exp = (context.ownerDocument || context).createExpression(exp, function (prefix) { return namespace[prefix] || document.createNSResolver((context.ownerDocument == null ? context : context.ownerDocument).documentElement) .lookupNamespaceURI(prefix) || document.documentElement.namespaceURI; }); switch (type) { case String: return exp.evaluate( context, XPathResult.STRING_TYPE, null ).stringValue; case Number: return exp.evaluate( context, XPathResult.NUMBER_TYPE, null ).numberValue; case Boolean: return exp.evaluate( context, XPathResult.BOOLEAN_TYPE, null ).booleanValue; case Array: var result = exp.evaluate( context, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null ); var ret = []; for (var i = 0, len = result.snapshotLength; i < len; ret.push(result.snapshotItem(i++))); return ret; case undefined: var result = exp.evaluate(context, XPathResult.ANY_TYPE, null); switch (result.resultType) { case XPathResult.STRING_TYPE : return result.stringValue; case XPathResult.NUMBER_TYPE : return result.numberValue; case XPathResult.BOOLEAN_TYPE: return result.booleanValue; case XPathResult.UNORDERED_NODE_ITERATOR_TYPE: { // not ensure the order. var ret = []; var i = null; while (i = result.iterateNext()) { ret.push(i); } return ret; } } return null; default: throw(TypeError("$X: specified type is not valid type.")); } } function get(u) { with( new XMLHttpRequest() ) { open("GET", u, false); send(""); return responseText } } // utility functions. function createHTMLDocumentByString(str) { var html = str.replace(/<!DOCTYPE.*?>/, '').replace(/<html.*?>/, '').replace(/<\/html>.*/, '') var htmlDoc = document.implementation.createDocument(null, 'html', null) var fragment = createDocumentFragmentByString(html) try { fragment = htmlDoc.adoptNode(fragment) } catch(e) { fragment = htmlDoc.importNode(fragment, true) } htmlDoc.documentElement.appendChild(fragment) return htmlDoc } function createDocumentFragmentByString(str) { var range = document.createRange() range.setStartAfter(document.body) return range.createContextualFragment(str) } // open http://www.behance.net/ $x('//div[contains(concat(" ",@class," ")," hentry ")]/h3/a').map( function (e) { return e.href; } ).slice(0,1).map( function (u) { var doc = createHTMLDocumentByString(get(u)) var r; r = $X( '//div[contains(concat(" ",@class," ")," post-body ")]/div/img' , doc) return r; } )