Extracting a Trello board as markdown

(or "web scraping from the chrome console, with jquery")

Assuming you use Trello and the Chrome browser, here's a technique for extracting a trello board onto your clipboard as plain text.

Navigate to the Trello board you want to grab, and bring up the chrome developer tools ([F12], or [Ctrl]+[Shift]+[I], or Tools → Developer Tools)

Go to the console (chrome console icon is a greater than followed by an equivalence indicator) -- and enter this piece of javascript. (Don't read it.... just enter it... trust me).

var s = [];var x;s.push("# " + $("#board-header").children()[0].innerText); $(".list:has(.list-title)").each(function() { x = this.innerHTML; s.push("## " + $(this).find(".list-title")[0].innerText);$(this).find(".list-card-title").each(function() { s.push("* " + this.innerText); }); }); copy(s.join("\n"));

Okay -- spaced out over a couple of lines it reads:


var s = [];
s.push("# " + $("#board-header").children()[0].innerText); 
$(".list:has(.list-title)").each(function() { 
    s.push("## " + $(this).find(".list-title")[0].innerText);
    $(this).find(".list-card-title").each(function() { 
        s.push("* " + this.innerText);
    });
}); 
copy(s.join("\n"));

The whole trello board will now be on your clipboard, in nature's favorite format: markdown.

Use the intrinsic 'copy' function to copy a value to the clipboard

One lesson I learnt while putting this together: you can use copy in the console to put a value onto the clipboard. This doesn't work in regular pages, for security reasons.

Inject jQuery into a page

If you want to use this kind of data-extraction technique on a page that doesn't have jQuery, then you'll want a simple technique for injecting jQuery into a page.

Just pop down to the console and paste this:

var script = document.createElement("script");
script.src = "http://code.jquery.com/jquery-latest.min.js";
document.body.appendChild(script);

jQuery will now be available on that page, and you can sizzle to your heart's content.

Caveats:

  1. You may first want to make sure jquery isn't already loaded.
  2. And you have to make sure the 'script' variable doesn't overwrite any existing variable of the same name.
  3. You may want a specific jQuery version.
  4. Use at your own risk, no warranty or replacement for lost limbs etc.
 

I'm currently writing a book about how to build your first product. If building a product is something you'd like to do, then sign up to be notified when the book is available.

Your comment, please?

Your Name
Your Url (optional)
Note: I may edit, reuse or delete your comment. Don't be mean.