• Stars
    star
    131
  • Rank 275,867 (Top 6 %)
  • Language
    Python
  • License
    MIT License
  • Created about 4 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Tableau scraper python library. R and Python scripts to scrape data from Tableau viz

Tableau Scraper

PyPI CI codecov License

Python library to scrape data from Tableau viz

R library is under development but a script is available to get the worksheets, see this

Python

Install

pip install TableauScraper

Usage

Get worksheets data

from tableauscraper import TableauScraper as TS

url = "https://public.tableau.com/views/PlayerStats-Top5Leagues20192020/OnePlayerSummary"

ts = TS()
ts.loads(url)
workbook = ts.getWorkbook()

for t in workbook.worksheets:
    print(f"worksheet name : {t.name}") #show worksheet name
    print(t.data) #show dataframe for this worksheet

Try this on repl.it

Get a specific worksheet

from tableauscraper import TableauScraper as TS

url = "https://public.tableau.com/views/PlayerStats-Top5Leagues20192020/OnePlayerSummary"

ts = TS()
ts.loads(url)

ws = ts.getWorksheet("ATT MID CREATIVE COMP")
print(ws.data)

select a selectable item

from tableauscraper import TableauScraper as TS

url = "https://public.tableau.com/views/PlayerStats-Top5Leagues20192020/OnePlayerSummary"

ts = TS()
ts.loads(url)

ws = ts.getWorksheet("ATT MID CREATIVE COMP")

# show selectable values
selections = ws.getSelectableItems()
print(selections)

# select that value
dashboard = ws.select("ATTR(Player)", "Vinicius Jรบnior")

# display worksheets
for t in dashboard.worksheets:
    print(t.data)

Try this on repl.it

set parameter

Get list of parameters with workbook.getParameters() and set parameter value using workbook.setParameter("column_name", "value") :

from tableauscraper import TableauScraper as TS

url = "https://public.tableau.com/views/PlayerStats-Top5Leagues20192020/OnePlayerSummary"

ts = TS()
ts.loads(url)
workbook = ts.getWorkbook()

# show parameters values / column
parameters = workbook.getParameters()
print(parameters)

# set parameters column / value
workbook = workbook.setParameter("P.League 2", "Ligue 1")

# display worksheets
for t in workbook.worksheets:
    print(t.data)

Try this on repl.it

It's possible to override the parameter name used in the API requests using inputParameter, which is different from the input name:

wb = wb.setParameter(inputName=None, value="Ligue 1",
                     inputParameter="[Parameters].[P.League (copy)_1642969456470679625]")

set filter

Get list of filters with worksheet.getFilters and set filter value using worksheet.setFilter("column_name", "value"):

from tableauscraper import TableauScraper as TS

url = 'https://public.tableau.com/views/WomenInOlympics/Dashboard1'
ts = TS()
ts.loads(url)

# show original data for worksheet
ws = ts.getWorksheet("Bar Chart")
print(ws.data)

# get filters columns and values
filters = ws.getFilters()
print(filters)

# set filter value
wb = ws.setFilter('Olympics', 'Winter')

# show the new data for worksheet
countyWs = wb.getWorksheet("Bar Chart")
print(countyWs.data)

Try this on repl.it

More advanced filtering options

  • You can specify dashboardFilter=True in order to use dashboard-categorical-filter API instead of categorical-filter-by-index API (related)

  • When using dashboardFilter=True you can skip the filter value check usin noCheck=True (related)

  • You can discard membershipTarget property from being sent in setFilter using setFilter('COLUMN','VALUE', membershipTarget=False) (related)

  • You can specify multiple filters for filters that enable that feature using setFilter('COLUMN', ['VALUE1','VALUE2'])

  • You can specify a "filter-delta" filter type adding the parameter filterDelta=True like the following setFilter('COLUMN','VALUE', filterDelta=True). This will discard all filters and add the one corresponding to ['VALUE'] in this case. This is helpful when all or some filters are selected by default, and you want to unselect them. The default behaviour (filterDelta=False) is filter-replace which sometimes doesn't work when filter multi-selection is possible in the dashboard. example

  • In last recourse, you can use indexValues property to directly specify the indices (if there is a bug in the library or anything comes up): setFilter('COLUMN', [], indexValues=[0,1,2])

Story points

Some Tableau dashboard have storypoints where you can navigate. To list the storypoints and go to a specific storypoints:

from tableauscraper import TableauScraper as TS

url = 'https://public.tableau.com/views/EarthquakeTrendStory2/Finished-Earthquakestory'
ts = TS()
ts.loads(url)
wb = ts.getWorkbook()

print(wb.getStoryPoints())
print("go to specific storypoint")
sp = wb.goToStoryPoint(storyPointId=10)

print(sp.getWorksheetNames())
print(sp.getWorksheet("Timeline").data)

Try this on repl.it

Level drill Up/Down

On some graph/table, there is a drill up/down feature used to zoom in or out data like this drill up/down

from tableauscraper import TableauScraper as TS

url = 'https://tableau.azdhs.gov/views/ELRv2testlevelandpeopletested/PeopleTested'
ts = TS()
ts.loads(url)
wb = ts.getWorkbook()

sheetName = "P1 - Tests by Day W/ % Positivity (Both) (2)"

drillDown1 = wb.getWorksheet(sheetName).levelDrill(drillDown=True, position=1)
drillDown2 = drillDown1.getWorksheet(sheetName).levelDrill(drillDown=True, position=1)
drillDown3 = drillDown2.getWorksheet(sheetName).levelDrill(drillDown=True, position=1)

print(drillDown1.getWorksheet(sheetName).data)
print(drillDown2.getWorksheet(sheetName).data)
print(drillDown3.getWorksheet(sheetName).data)

Try this on repl.it

The position parameter is default to 0. It doesn't seem to be present in the json configuration. If the default is not working try incrementing it or checkout the network tabs using Chrome devtools.

Download CSV data

For Tableau URL that have the download feature enabled, you can download full data using:

from tableauscraper import TableauScraper as TS

url = 'https://public.tableau.com/views/WYCOVID-19Dashboard/WyomingCOVID-19CaseDashboard'
ts = TS()
ts.loads(url)
wb = ts.getWorkbook()
data = wb.getCsvData(sheetName='case map')

print(data)

Note that in some Tableau server, the prefix used in the API url is different. As it's set in the javascript, it must be set manually if it's not the same as public.tableau.com like:

wb.getCsvData(sheetName='worksheet1', prefix="vud")

The prefix values, I've encountered are: vud and vudcsv. The default is vudcsv.

Try this on repl.it

Download Cross Tab data

For Tableau URL that have the crosstab feature enabled, you can download the crosstab using:

from tableauscraper import TableauScraper as TS

url = "https://tableau.soa.org/t/soa-public/views/USPostLevelTermMortalityExperienceInteractiveTool/DataTable2"

ts = TS()
ts.loads(url)
wb = ts.getWorkbook()

wb.setParameter(inputName="Count or Amount", value="Amount")

data = wb.getCrossTabData(
    sheetName="Data Table 2 - Premium Jump & PLT Duration")

print(data)

Go to sheet

Get list of all sheets with subsheets visible or invisible, ability to send a go-to-sheet command (dashboar button) :

from tableauscraper import TableauScraper as TS

url = "https://public.tableau.com/views/COVID-19VaccineTrackerDashboard_16153822244270/Dosesadministered"
ts = TS()
ts.loads(url)
workbook = ts.getWorkbook()

sheets = workbook.getSheets()
print(sheets)

nycAdults = workbook.goToSheet("NYC Adults")
for t in nycAdults.worksheets:
    print(f"worksheet name : {t.name}")  # show worksheet name
    print(t.data)  # show dataframe for this worksheet

Render tooltip

Get the tooltip html output when render-tooltip-server API is called. This is particularly useful when dealing with server side rendering dashboard:

from tableauscraper import TableauScraper as TS

url = "https://public.tableau.com/views/CMI-2_0/CMI"

ts = TS()
ts.loads(url)
workbook = ts.getWorkbook()
ws = workbook.getWorksheet("US Map - State - CMI")

tooltipHtml = ws.renderTooltip(x=387, y=196)
print(tooltipHtml)

Sample usecases

Server side rendering

If the tableau url you're working on is using server side rendering, data can't be extracted as is.

You can checkout if your tableau url is using server side rendering by opening chrome development console / network tab. You would notice the API calls have renderMode properties set to render-mode-server:

server side render mode

Server side rendering means that no data is sent to the browser. Instead, the server is rendering the tableau chart using images only and detects selection using mouse coordinates.

To extract the data, one thing that has worked with some tableau url was to trigger a specific filter that is not server-side-rendered. You can checkout the network tab on Chrome development console to check if the filter call is using or not server-side rendering or client-side-rendering with renderMode:

client side rendering

If the filter is only using client side rendering, you can list all filters and perform the filter for each value. This technique only works if the tableau data has "cleared" the filter by default otherwise the data is already cached when the tableau data is loaded, and since it's using server side rendering you can't access this data

Checkout the following repl.it for examples with tableau url using server side rendering:

Testing Python script

To discover all worksheets, selectable columns and dropdowns, run prompt.py script under scripts directory :

git clone [email protected]:bertrandmartel/tableau-scraping.git
cd tableau-scraping/scripts

#get worksheets data
python3 prompt.py -get workbook -url "https://public.tableau.com/views/PlayerStats-Top5Leagues20192020/OnePlayerSummary"

#select a selectable item
python3 prompt.py -get select -url "https://public.tableau.com/views/MKTScoredeisolamentosocial/VisoGeral"

#set a parameter
python3 prompt.py -get parameter -url "https://public.tableau.com/views/COVID-19DailyDashboard_15960160643010/Casesbyneighbourhood"

Settings

TableauScraper class has the following optional parameters :

Parameters default value description
logLevel logging.INFO log level
delayMs 500 minimum delay in millis between api calls

R

under R directory :

Rscript tableau.R

R library is under development

Dependencies

requirements.txt

  • pandas
  • requests
  • beautifulsoup4

Stackoverflow Questions

See those stackoverflow posts about this topic

More Repositories

1

speed-test-lib

โ˜๏ธ JSpeedTest : speed test client library for Java/Android
Java
381
star
2

youtubetv

๐Ÿ“บ YouTube embedded player library for Android TV
Java
60
star
3

aws-ssm-session

Javascript library for starting an AWS SSM session compatible with Browser and NodeJS
JavaScript
50
star
4

javacard-gradle-plugin

๐Ÿ”‘ Gradle plugin for JavaCard development
Groovy
32
star
5

docker-jenkins-android

๐Ÿณ A jenkins docker image for Android development
Shell
30
star
6

bluetooth-remote-control

Bluetooth Low Energy remote control based on NRF 51 DK board with an additional display capability
Java
29
star
7

javacard-tutorial

Examples from Eric Vรฉtillard's tutorial re-arranged in a Gradle project
Java
29
star
8

aram-applet

JavaCard implementation of GlobalPlatform Access Rule Application Master Applet
Java
28
star
9

btsnoop-decoder

C++ Bluetooth snoop file streaming decoder
C++
28
star
10

openwrt-mwan-config

OpenWrt multi wan working configuration on a TP-Link Archer C7 v2 router
26
star
11

fadecandy-android

โœจ Fadecandy server library to manage your Fadecandy USB controlled LED driver on Android
Kotlin
25
star
12

pcapng-decoder

Java PCAPNG decoder library
Java
25
star
13

hci-debugger

Android app decoding/displaying Bluetooth HCI packets
Java
24
star
14

bluetooth-hci-decoder

๐Ÿ“ฑ C++ Bluetooth HCI decoder library
C++
23
star
15

plot-sdl

plot graphic lib using SDL2
C
21
star
16

ssl-cert-generator-lib

OpenSSL C++ X509 certificate generator library
C
19
star
17

sim-password-wallet

Android application interacting with a JavaCard applet installed on SIM card
Java
17
star
18

metec-braille-driver

โœ‹ Driver for Metec Braille-line 20 Cell module for Arduino & Raspberry PI
C++
17
star
19

android-curl-builder

Set of bash scripts used to cross compile curl & its dependencies for Android platform
Shell
17
star
20

digest-auth-session-cpp

C++ digest authentication/session library for server
C++
15
star
21

kibana-oauth2-proxy

oauth2 proxy docker config for Kibana 6.1.1 with searchguard or xpack
Shell
14
star
22

ndk-curl-sample

Sample project using libcurl in a small Android NDK project
C
13
star
23

ffmpeg-image-sequencer

Create MPEG4 video from JPG images and append JPG images to MPEG4 videos using FFmpeg
Shell
11
star
24

wlan-decoder-java

Java WLAN 802.11 decoder
Java
10
star
25

callflow-workshop

ReactJS powered material dashboard to build, share & download sequence diagram
JavaScript
10
star
26

bboxapi-router

๐Ÿ“ถ Bbox Router API client library for Kotlin/Java/Android
Kotlin
9
star
27

dotti-bluetooth-android

Android app interacting with Dotti bluetooth device
Java
9
star
28

apk-checker

Java APK integrity checker and key comparator
Java
9
star
29

pcsc-android-emulator

SmartCard Android Emulator binaries & build instructions
9
star
30

aws-admin

โ˜๏ธ An admin dashboard for AWS using the AWS API under the hood
Vue
9
star
31

bluetooth-le-analyzer

Android app measuring Bluetooth advertising packet reception rate using one RFduino module
Java
9
star
32

android-service-template

Android project template featuring multi process service oriented architecture
Java
8
star
33

notti-library

Android app interacting with Notti bluetooth device
Java
7
star
34

iotf-android

IBM IoT foundation Messaging library for Android
Java
7
star
35

websocket-non-blocking

C++ websocket non-blocking server library for Qt4/Qt5
C++
7
star
36

gitlab-backup

๐Ÿ“ Backup script for Gitlab with CRON and docker support
Shell
6
star
37

websocket-java

Websocket Server/Client Java implementation
Java
6
star
38

lfsr-reverse

Study about hacking a device's authentication based on LFSR
C
6
star
39

raspberry-spycam

Stream from a Raspberry PI camera module to Android RTSP client
Shell
5
star
40

ustream-dl

Experimental python script for downloading a stream (which has ended) from ustream.tv
Python
5
star
41

opc-java

Fork of Open Pixel Control library for Java/Android from https://github.com/scanlime/fadecandy/tree/master/examples/java
Java
5
star
42

media-optimizer

Automatically optimize your images & videos hosted on AWS S3 when an S3 event is detected
Go
5
star
43

multi-event-library

Android library used to catch a range of event types (volume, screen state, incoming call, SMS, Wifi connection etc...)
Java
5
star
44

pusher

๐Ÿ”ฒ Mechanical wall switch button pusher securely controlled via Bluetooth LE
Java
5
star
45

flower-power-android

Android app interacting with Flower Power Bluetooth device
Java
5
star
46

sms-group-sender

Android app used to send customized SMS to multiple group of contacts based on message topic
Java
4
star
47

http-endec

Http encoder/decoder for Java/Android
Java
4
star
48

bixi-android

Android library interacting with Bixi bluetooth device
Kotlin
4
star
49

caipy-dashboard

ReactJS material dashboard featuring Ad detection in TV programs
JavaScript
4
star
50

radiotap-decoder-java

Radiotap Header decoder in Java
Java
4
star
51

st7735-raspberry

โœจ A port of ST7735 Arduino library to Raspberry PI
C++
4
star
52

w230st-osx

Clover configuration for OS X El Capitan on laptop Clevo W230ST
Shell
4
star
53

covid19-nyc-vaccine-tracker

Covid19 NYC Vaccine Tracker data extracted from Tableau
Python
4
star
54

emrine-arduino

๐Ÿ”“ Use emrine.com QR code based access control solution on Arduino
C++
3
star
55

gitlab-docker-compose

A fully configurable Gitlab CE docker-compose build
Shell
3
star
56

android-googlesignin

Sample project featuring Google Signin sample code
Java
3
star
57

developer-portfolio

A one page configurable HTML/AngularJS theme for developers
CSS
3
star
58

docker-openvpn

A minimal OpenVpn docker image to be run with an already existing configuration
Shell
3
star
59

http-streaming-decoder

C++ HTTP streaming decoder library for Qt4/Qt5
C++
2
star
60

gcalendar-notification-server

Google calendar embedded notification server
Java
2
star
61

bluetooth-advert-viewer

Android Bluetooth advertizing frame viewer
Java
2
star
62

vpn-http-proxy

From a Kubernetes cluster, get Internet access from a local Raspberry PI through a VPN connection
HCL
2
star
63

rfdroid-scanparam

fork of RFdroid to include BLE set scan interval / scan window API (from a patched version of AOSP)
Java
2
star
64

google-cross-client-node

Cross-client Identity for Google authentication on Node JS server
JavaScript
2
star
65

youtube-watch-later

Sample code for adding a video to Watch Later playlist
PHP
2
star
66

socket-multiplatform

Multi-platform Socket connection types
C++
2
star
67

bluedroid-build

Standalone build for Bluedroid
Shell
2
star
68

webradio-tv-app

A sample Android TV application used to play webradio streaming
Java
2
star
69

cloud-admin

Database admin interface with dynamic model configuration supporting table relations through datatable views powered by React
JavaScript
2
star
70

cloudformation-templates

๐Ÿ“š A collection of AWS cloudformation templates
Go
1
star
71

google-cross-client-android

Cross-client Identity for Google authentication on Android
Java
1
star
72

arduino-makefile

๐Ÿ’ป Build your Arduino project with a single Makefile
Makefile
1
star
73

node-app-proxy

Sample nodejs app with an apache proxy (including websocket)
HTML
1
star
74

bboxapi-voicemail

Experimental Java/Android client library for unofficial Bbox VoiceMail API
Java
1
star
75

bboxapi-stb

๐Ÿ“บ Bbox Miami API client library for Kotlin/Java/Android
Kotlin
1
star
76

css-readme

Embed custom html badge using css in svg
1
star
77

pusher-client-events

Sample project featuring client events between Android & webapp using Pusher
Kotlin
1
star
78

adafruit-oled-st7735-dk51

โœจ Integration of Adafruit OLED ST7735 1.8 display on Nordic Semiconductor NRF51 DK board
C
1
star
79

node-download-server

Experimental Node JS HTTP/Socket IO server to download small to large amount of tar.gz files and unpack these to a specific directory
JavaScript
1
star
80

rfduino-makefile

Build your RFduino project with a single Makefile
Makefile
1
star
81

ssl-cert-dashboard

Dashboard of SSL certificates with QT4 server / mongoDB back-end
C++
1
star
82

fritzing-parts

A collection of Fritzing parts for my own projects
1
star
83

braille-dot-converter

โœ‹ React application converting Braille pattern to binary/hex easily, bit index is also configurable
JavaScript
1
star
84

mobileconnect

Library implementing Mobile Connect API written in GO
Go
1
star
85

androidtv-access-point

Android TV application used to configure your Wifi Access Point (Android L only)
Java
1
star
86

vue-basic-captcha

๐Ÿ”ง Template project of a Vue.js application with basic authentication & captcha integration in Go
Vue
1
star