Library to get data from Tableau Viz
Project description
Tableau Scraper
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
- 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)
- 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)
- 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)
- 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
Sample usecases
- https://replit.com/@bertrandmartel/TableauOregonCovid
- https://replit.com/@bertrandmartel/TableauCovidIndia
- https://replit.com/@bertrandmartel/TableauCovidArizona
- https://replit.com/@bertrandmartel/TableauIllinoisOpioId
- https://replit.com/@bertrandmartel/TableauCovidNY
- https://replit.com/@bertrandmartel/TableauCovidNCDHHS
- https://replit.com/@bertrandmartel/TableauCovidWisconsin
- https://replit.com/@bertrandmartel/TableauScrapeNewspaper
- https://replit.com/@bertrandmartel/TableauStoryPoints
- https://replit.com/@bertrandmartel/TableauCovidOhio
- https://replit.com/@bertrandmartel/TableauCovidSouthCarolina
- https://replit.com/@bertrandmartel/TableauCovidNewHampshire
- https://replit.com/@bertrandmartel/TableauCovidNewJersey
Testing Python script
To discover all worksheets, selectable columns and dropdowns, run prompt.py script under scripts directory :
git clone git@github.com:bertrandmartel/tableau-scraping.git
cd tableau-scraping/scripts
#get worksheets data
python3 prompt.py -get workbook -url "https://public.tableau.com/views/COVID-19inMissouri/COVID-19inMissouri"
#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 actions (select/dropdown request) |
R
under R directory :
Rscript tableau.R
R library is under development
Stackoverflow Questions
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file TableauScraper-0.1.5.tar.gz.
File metadata
- Download URL: TableauScraper-0.1.5.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.22.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aedc67570f034f0bf4de5674212b61777fe6405dcf439d0b26ee9f81f804178f
|
|
| MD5 |
5dce6c6830860cfd0978292c9c69d9c6
|
|
| BLAKE2b-256 |
61a40f42c74ba9c70c5c0c155b6dee57e597d08d9abce720871898f6275c2c92
|
File details
Details for the file TableauScraper-0.1.5-py3-none-any.whl.
File metadata
- Download URL: TableauScraper-0.1.5-py3-none-any.whl
- Upload date:
- Size: 15.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.22.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
490db8aea65e71e9955f2be2173c9ffa802e364269a75385e18cbeb568b750f6
|
|
| MD5 |
e6b20702f4c409a9802834e1f6274615
|
|
| BLAKE2b-256 |
cb46fba5c6b66776471383239cd4b1a8cd6b54e0c352507a75d10fc49fd63b9d
|