artoo.js The client-side scraping companion.

artoo.save


artoo.js’ save module enables you to download various things from JavaScript.

If your browser warns you about the webpage trying to download several items, just tell him it’s gonna be ok and you should not be bothered again.

Note: every methods below can take the same parameters object as artoo.save. They are just not documented each time.



artoo.save

Download data according to given parameters. This function should only be used if the next functions cannot satisfy your needs.

// Basic signature
artoo.save(data, [params]);

// Alternative signature
artoo.save(data, [filename]);

Note that if the second argument is a string it will be considered as params.filename. This is true for every othe save method.

Arguments

  • data string : data to download.
  • params ?object : an object that may contain the following properties:
    • mime ?string : mime type of the file to download. Note that artoo provide some shortcuts for popular types such as json, csv text and html.
    • encoding ?string : encoding of the file to download.
    • filename ?string : name of the file to download.
    • revoke ?boolean [true] : whether you want the blob URL created to download your file revoked afterwards.

artoo.saveJson

Dowload a JavaScript variable or a JSON string as a JSON file.

artoo.saveJson(data, [params]);

Additional parameters

  • pretty ?boolean [false] : should the ouput JSON file be pretty-printed?
  • indent ?integer [2] : By how many spaces should we indent the JSON file?

Example

artoo.saveJson({hello: world}, {filename: 'hello-world.json'});

artoo.savePrettyJson

Dowload a JavaScript variable or a JSON string as a pretty-printed JSON file.

artoo.savePrettyJson(data, [params]);

This is the same as doing

artoo.saveJson(data, {pretty: true});

artoo.saveCsv

Download an array of array, an array of objects or a string as a CSV file.

artoo.saveCsv(data, [params]);

Additional parameters

  • delimiter ?string [,] : the field delimiter.
  • escape ?string ["] : the escape character.
  • order ?array : the wanted keys and their order if you pass an array of object as data.
  • headers ?boolean or ?array : whether you want headers and if you want them customized.

Example

var persons =[
   {
     firstname: 'Caroline',
     lastname: 'Williams'
   },
   {
     filename: 'Steven',
     lastname: 'Douglas'
   }
];

artoo.saveCsv(persons);

For more precisions, refer to the artoo.writers.csv method.


artoo.saveTsv

This method is an alias of the saveCsv one and simply overrides the delimiter with \t.

artoo.saveTsv(data, [params]);

artoo.saveYaml

Dowload a JavaScript variable as a YAML file.

artoo.saveYaml(data, [params]);

artoo.saveXml

Download a XML file from a string, a jQuery selector or a DOM document.

artoo.saveXml(htmlData, [params]);

Examples

artoo.saveXml($('#a_div_id'), {filename: 'div.html'});
artoo.saveXml(document);

artoo.saveSvg

Download a SVG file from a jQuery selector.

artoo.saveSvg(svgData, [params]);

This method is an alias of artoo.saveXml.


artoo.saveHtml

Download a HTML file from a string, a jQuery selector or a DOM document.

artoo.saveHtml(htmlData, [params]);

This method is an alias of artoo.saveXml.


artoo.savePageHtml

Download the page’s current Html.

artoo.savePageHtml([params]);

artoo.saveStore

Save the content of the local storage as a JSON file. You can also alternatively select to download only the part corresponding to a key.

artoo.saveStore([params]);

Additional Parameters

  • key ?string : the precise key to save.

Example

artoo.saveStore({key: 'your-needed-key'});

artoo.saveResource

Save the resource located at the given url.

artoo.saveResource(url, [params]);

Example

artoo.saveResource('http://url-of-a-random-audio-file.mp3', {
  filename: 'MyAwesomeMusic.mp3'
});

artoo.saveResource('/public/css/style.css');

artoo.saveImage

Save an image corresponding either to a css or a jQuery selector.

artoo will name your file [alt-attribute].extension by default if you do not provide a filename parameter.

artoo.saveImage(selector, [params]);

Example

artoo.saveImage('#an_image_id');