Search code examples
javascriptbookmarkletweb-scraping

Web scraping with bookmarklet?


I'd like to use a bookmarklet to gather toghether a few resouces from different webpages.
i.e, instead of using some browser extensions to get the html elements from the pages, I would like to use some javascript bookmarklet to capture the code from the sites.

[Edit] How do I get the html elements from the page with JavaScript bookmarklet?
The question is about getting the html inner code with bookmarklet, not about bookmarklet in general.


Solution

  • You don't need any libraries to do this. Just create your functionality in Firebug or Chrome Inspector and then format it on one line like this:

    javascript:(function(){alert(1);})();

    Copy and paste this to the location bar and hit enter to execute it. Replace the alert(1); with your code. We wrap it in a self-executing anonymous function or else the response of what you execute would replace the web page.

    If your code is really long you can write it all in an external javascript file and where you see the alert above just create a script tag with your src and append it to the page.