# Automated raw CSV export of visualization \[Kibana 4\]

**URL:** <https://discuss.elastic.co/t/automated-raw-csv-export-of-visualization-kibana-4/115869>\
**Category:** Kibana\
**Created:** [January 17, 2018, 11:20am UTC](https://discuss.elastic.co/t/automated-raw-csv-export-of-visualization-kibana-4/115869 "2018-01-17T11:20:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![xenoid](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xenoid/32/20672_2.png) [@xenoid](https://discuss.elastic.co/u/xenoid)\
**Post date:** [January 17, 2018, 11:20am UTC](https://discuss.elastic.co/t/automated-raw-csv-export-of-visualization-kibana-4/115869/1 "2018-01-17T11:20:43Z")

</div>

I want to automate the generation of a csv file that usually would be downloaded by clicking on the "Raw" button on the bottom of the page.  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/0/5/057fbaec1d9f7fda6857f3e13679ae74e25b8125.png)

It would be as simple as

```
//Folding up the menu (in Javascript)
$("i.fa.fa-chevron-up:last").click();
//and clicking the button.
$("[ng-click='aggTable.exportAsCsv(false)']").click();

```

In Chrome the csv file is now being downloaded from a blob url.  
But Chrome (with GUI) can't be controlled via commandline as far as I know.

But neither PhantomJS nor CasperJS allow me to run my commands and **download** the file.

Could you help me with this? 🤔

Edit: The use of X-Pack currently is no option, sadly.

---

<div class="post-metadata">

**Author:** ![chrisronline](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chrisronline/32/28230_2.png) [@chrisronline](https://discuss.elastic.co/u/chrisronline)\
**Post date:** [January 17, 2018, 4:45pm UTC](https://discuss.elastic.co/t/automated-raw-csv-export-of-visualization-kibana-4/115869/2 "2018-01-17T16:45:34Z")

</div>

Hi @xenoid,

What's happening in PhantomJS/CasperJS when you execute the click on the button?

---

<div class="post-metadata">

**Author:** ![xenoid](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xenoid/32/20672_2.png) [@xenoid](https://discuss.elastic.co/u/xenoid)\
**Post date:** [January 18, 2018, 7:02am UTC](https://discuss.elastic.co/t/automated-raw-csv-export-of-visualization-kibana-4/115869/3 "2018-01-18T07:02:26Z")

</div>

A simple click of the button sadly does not do anything.

I've been told that PhantomJS actually does not support downloading files directly.  
The fact that it is generated and downloaded via Eli Grey's FileSaver.js wont make it simpler.

I'll take a look at chromedriver. It seems to be more sophisticated.

---

<div class="post-metadata">

**Author:** ![xenoid](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xenoid/32/20672_2.png) [@xenoid](https://discuss.elastic.co/u/xenoid)\
**Post date:** [January 18, 2018, 11:01am UTC](https://discuss.elastic.co/t/automated-raw-csv-export-of-visualization-kibana-4/115869/4 "2018-01-18T11:01:07Z")

</div>

I gave up on PhantomJS and used Selenium Webdriver in combination with Python.  
Heres my solution:

```
import time
import os
from selenium import webdriver

#xenoid 18.01.2018

#Starting the driver
chromeOptions = webdriver.ChromeOptions()

#Download directory
prefs = {"download.default_directory" : "C:/temp/KibanaExportToCSV/"}
chromeOptions.add_experimental_option("prefs",prefs)
driver = webdriver.Chrome('C:\chromedriver\chromedriver.exe', chrome_options=chromeOptions)
driver.get("_YOUR LINK TO THE VISUALIZATION HERE_");
#Time it takes for the visualization to load
time.sleep(15)
#Open the footer menu
menu = driver.find_element_by_css_selector("i.fa.fa-chevron-up")
menu.click()
time.sleep(1)
#Click the button
exportToCsv = driver.find_element_by_css_selector(".visualize-spy-content a.small[ng-click='aggTable.exportAsCsv(false)']")
exportToCsv.click()
time.sleep(3)
driver.quit()

```

Hope this is useful to someone 🙂

---

<div class="post-metadata">

**Author:** ![chrisronline](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chrisronline/32/28230_2.png) [@chrisronline](https://discuss.elastic.co/u/chrisronline)\
**Post date:** [January 18, 2018, 2:17pm UTC](https://discuss.elastic.co/t/automated-raw-csv-export-of-visualization-kibana-4/115869/5 "2018-01-18T14:17:09Z")

</div>

Great!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 15, 2018, 2:17pm UTC](https://discuss.elastic.co/t/automated-raw-csv-export-of-visualization-kibana-4/115869/6 "2018-02-15T14:17:12Z")

</div>

Closed on February 15, 2018, 2:17pm UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
