'Scraping data from tabelau dashboard and filtering with dropdown boxes (python)

I'm trying to scrape data from the website below from a tableau dashboard. While it works, I'd also like to filter the data (from the worksheet Mapa) by year (Año) and sex (Sexo) based on the dropdown boxes. I suspect that such filtering can be done through the setFilter() function with the argument dashboardFilter=True but am having trouble implementing it.

I think the problem is because the names of the filters on the dashboard differ from the names in the actual worksheets and in some cases, do not even exist in the specific worksheet I'm looking for. I've looked into similar issues like https://github.com/bertrandmartel/tableau-scraping/issues/26 but cant quite get it to work. Would someone be able to help? Thankyou in advance.

Code is below:

from tableauscraper import TableauScraper as TS
import pandas as pd

url = "https://public.tableau.com/views/DashboardRegional_15811027307400/DashboardRegional?:embed=y&:showVizHome=no&:host_url=https%3A%2F%2Fpublic.tableau.com%2F&:embed_code_version=3&:tabs=no&:toolbar=no&:animate_transition=yes&:display_static_image=no&:display_spinner=no&:display_overlay=yes&:display_count=yes&publish=yes&:loadOrderID=0"

ts = TS()
ts.loads(url)
wb=ts.getWorkbook()
sheetName = "Mapa"

ws = wb.getWorksheet(sheetName)
print(ws.data)
# I cant filter by these categories
# wb = ws.setFilter("Sexo", "Hombres", dashboardFilter=True)
# ws = wb.getWorksheet(sheetName)
# wb = ws.setFilter("Año", 2020, dashboardFilter=True)
# ws = wb.getWorksheet(sheetName)
# print(ws.data)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source