By the end of this tutorial, you will have a short Python script that pulls practitioner listings from Doctoralia Spain into structured JSON: full name, profile URL, primary specialization, practice street address, city, province, rating, number of patient reviews, listed services, and whether the listing has an online booking calendar.
Doctoralia lists practitioners across Spain. Finding every psychologist in Madrid, or every dentist in Valencia, means paging through result lists by hand and copying names and addresses into a spreadsheet. A small Actor on the Apify platform can do that paging for you and return one clean row per listing.
In this guide we use Python and the Apify Actor Doctoralia Scraper (reventadata/doctoralia-scraper). The Actor is not affiliated with Doctoralia. It reads public directory pages, so it needs no login.
Prerequisites
To follow this tutorial, you need:
-
Python 3.11 or newer, because
apify-client3.x requires it. - The Apify API client for Python:
pip install -U "apify-client~=3.0". - A free Apify account and your personal API token. Sign up for a free account, then copy your personal API token from your account settings in the Apify Console.
Set the token as an environment variable so it stays out of your script:
export APIFY_API_TOKEN="your_apify_token_here"
The script below is the only code you need.
What you'll achieve
At the end of the run, you get one dataset row per practitioner card that matched your search. You can export the rows as JSON, CSV or Excel, or read them directly in Python.
Example use case: you want a list of psychologists in Barcelona, with their addresses and review counts, to compare providers in one neighbourhood. Setting specialty to psicologo and city to barcelona gives you rows you can sort by opinionsCount or filter by province in a few lines of pandas.
Step 1: Open the Actor
Go to the Doctoralia Scraper page on the Apify Store. The page lists the input fields and the output fields. You can also start a run from the platform's web interface, but in this tutorial we start it from Python with the official apify-client SDK, so the same code runs again on any schedule you set.
Step 2: Set the search inputs
The Actor takes four inputs that matter for a basic search:
-
specialty: the specialty slug as it appears in a Doctoralia directory URL, for examplepsicologo,dentista,ginecologo,dermatologo,cardiologoormedico-general. The default ispsicologo. -
city: the city slug, for examplemadrid,barcelona,valenciaorsevilla. Useonlineto list practitioners who offer video consultations. The default ismadrid. -
maxItems: the maximum number of practitioner cards to collect. The default is100. -
maxPages: an optional limit on directory pages. The site shows roughly 20 to 34 doctor cards per page, somaxPagesis a second way to keep a run small.
Here is the input for a small first test:
import os
from apify_client import ApifyClient
# 1. Create the client with the token from your environment
client = ApifyClient(os.environ["APIFY_API_TOKEN"])
# 2. The search: a specialty and a city slug, capped at 10 cards
run_input = {
"specialty": "psicologo",
"city": "madrid",
"maxItems": 10,
"maxPages": 1,
}
An unknown specialty or city slug fails the run on page 1: the run ends as FAILED, and its log names the search URL.
Step 3: Pick the caps you need
The two caps work together. maxItems stops the run once that many rows are saved, even if more pages exist. maxPages stops the paging after that many directory pages. If you set neither, the default maxItems of 100 applies.
Two behaviours are worth knowing:
- A practitioner appears once per run. If the same ID shows up on a later page, the Actor skips it and does not write a second row.
- The
searchUrlfield records the directory search each row came from, so a mixed export still tells you which search produced which row.
Step 4: Run the Actor
Start the run and wait for it to finish:
print("Starting Doctoralia extraction...")
run = client.actor("reventadata/doctoralia-scraper").call(run_input=run_input)
if run is None or run.status != "SUCCEEDED":
status = run.status if run else "unknown"
raise SystemExit(f"Run did not succeed (status: {status}).")
# 3. Read the rows the run saved to its default dataset
items = client.dataset(run.default_dataset_id).list_items().items
print(f"Retrieved {len(items)} listings.")
The script waits for the run to finish, then reads its rows.
A run can also end as SUCCEEDED with zero rows. That happens when the search matches no listing, for example a city with no practitioners in that specialty. The status message in the run log says so, and the script above prints a count of zero.
Step 5: View and export the results
Iterate through the rows in Python:
for item in items:
print(f"{item['name']} | {item.get('specialization')} | {item.get('city')}")
if item.get("streetAddress"):
print(f" Address: {item['streetAddress']}")
print(f" Rating: {item.get('rating')} from {item.get('opinionsCount')} reviews")
print(f" Profile: {item['url']}")
print("-" * 50)
To save the rows as a file, write the list to JSON:
import json
with open("doctoralia_rows.json", "w", encoding="utf-8") as handle:
json.dump(items, handle, ensure_ascii=False, indent=2)
The ensure_ascii=False flag keeps accents such as Víctor and García readable in the file.
Understanding your results
Each row is one practitioner card. These are the fields you will use most:
-
id: Doctoralia's numeric ID for the practitioner or facility. Use it as a stable key between runs. -
nameandurl: the full name and the public profile URL on doctoralia.es. -
entityType:doctororfacility. In the 2026-11-19 capture, 2 of the 10 rows arefacility. -
specialization,specializationIdsandallSpecializations: the primary specialization, its numeric IDs, and every specialization or focus area the card lists. -
streetAddress,city,provinceandaddressId: the consultation address as the card shows it. -
isOnlineOnly:truewhen the practitioner offers online consultations only. -
rating(out of 5) andopinionsCount(the number of patient reviews). -
isFirstClassmarks a featured result.resultTypeis the result category the card carries. The 10 rows in the capture carryfirst-class,organic,new-client-enricherandfixed-slots-enricher-best. -
services: the consultation types listed on the card, such as "Consulta online". -
hasCalendarandhasCalendarWithSlots: two flags the card carries. All 10 rows in the capture aretruefor both. -
imageUrl: the profile photo URL, when the card has one. -
searchUrl: the directory search the row came from.
Here is one row from a capture dated 2026-11-19 (specialty psicologo, city madrid):
{
"id": "70548",
"name": "Víctor Alejandro Briones",
"url": "https://www.doctoralia.es/perfil/victor-alejandro-briones",
"entityType": "doctor",
"specialization": "Psicólogo",
"specializationIds": "60",
"allSpecializations": "Psicólogo",
"streetAddress": "Calle de Canarias 4",
"city": "Madrid",
"province": "Madrid",
"addressId": "225088",
"isOnlineOnly": false,
"rating": 5.0,
"opinionsCount": 93,
"isFirstClass": true,
"resultType": "first-class",
"services": [
"Consulta de psicología",
"Consulta online"
],
"imageUrl": "https://s3-eu-west-1.amazonaws.com/doctoralia.es/doctor/dbd5da/dbd5da568022a1f1ac4f4982f03dff1a_large.jpg",
"hasCalendar": true,
"hasCalendarWithSlots": true,
"searchUrl": "https://www.doctoralia.es/psicologo/madrid"
}
Two more rows from the same capture show the same shape with different values: one practitioner with 142 reviews, and one with 68. Every row carries the same keys.
Some fields are null on some rows. streetAddress is null when the card has no address, and services is null when the card lists none. Check for null before you sort or join on those fields.
Pro tips and advanced usage
-
Keep test runs small. Set
maxItemsto 10 andmaxPagesto 1 while you build the script. Raise both only when the output looks right. -
Split a large search by city. A single search covers one specialty in one city. To compare cities, run one search per city and keep the
searchUrlcolumn to tell them apart. -
Use
onlinefor teleconsultations. Thecityvalueonlinelists practitioners who offer video consultations. Filter onisOnlineOnlyif you only want those who work exclusively online. - Schedule it. Save the input as a task in the Apify Console and attach a schedule, or call the run from your own cron job with the same Python code.
-
Read the rating with its count. Look at
opinionsCountnext toratingbefore you rank practitioners.
Troubleshooting common issues
-
The run ends as FAILED with a message about a slug. The
specialtyorcityvalue is not in Doctoralia's URL format. Copy the value from a directory URL on doctoralia.es, such asdoctoralia.es/psicologo/madrid, and usepsicologoandmadrid. - The run is SUCCEEDED but the dataset is empty. The search matched nothing. Try a larger city or a broader specialty.
-
Some fields are null. Several fields are null on some rows, for example
streetAddress. Treat null as missing, not as a default value. - Where to look. The run log shows the search URL and the number of rows saved. The dataset tab in the Apify Console shows the same rows you read from Python.
Next steps
Start with a 10-row run, check the fields you need, then raise maxItems and add a schedule when the output is right. Once you have a clean JSON file, you can load it into a spreadsheet or a DataFrame.
For current pricing and details, see the Store page.
Helpful links:
About the author: reventadata builds and maintains marketplace scrapers on the Apify Store.
Top comments (0)