# ONPE Peru Elections Results Scraper (`acquistion-automation/onpe-peru-elections-scraper`) Actor

Scrapes official Peruvian election results from ONPE by geographic level and round. Returns votes, percentages, and candidate totals as flat rows.

- **URL**: https://apify.com/acquistion-automation/onpe-peru-elections-scraper.md
- **Developed by:** [Acquisition Automation Co.](https://apify.com/acquistion-automation) (community)
- **Categories:** Automation, Integrations, News
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $7.50 / 1,000 results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

### ONPE Peru Elections Results Scraper

**Scrape official Peru election results from ONPE, by department, province, or district, for both rounds of the 2021 general election.** Every row includes votes, percentages, and candidate totals, ready for CSV, JSON, Excel, or XML.

ONPE publishes Peru's official election results on its public web portal, but the data is spread across pages and not built for bulk analysis. This Actor reads the results directly, filtered by geographic level and election round, and returns each match in one fixed schema. No login, no API key, no manual copying.

| Who uses it | What they scrape ONPE Peru for |
|---|---|
| Political analysts | Compare vote distribution across departments and provinces |
| Journalists | Verify official counts for election coverage |
| Academic researchers | Build datasets for electoral studies |
| NGOs and observers | Monitor regional turnout and results |
| Data engineers | Feed election data into dashboards and models |

### What it does

This Actor collects official Peruvian election results from ONPE by geographic level and round, and returns each result as a flat row.

- 🗺️ **Geographic levels:** national, department, province, or district results.
- 🗳️ **Both rounds:** first round (Primera vuelta) and second round (Segunda vuelta).
- 📊 **Structured rows:** each result includes votes, percentages, and candidate totals.
- ⚡ **Bulk export:** up to one million results per run, in CSV, JSON, Excel, or XML.

Results export to CSV, JSON, Excel, or XML, or straight from the API.

### What you can do with ONPE Peru data

**📈 Track regional voting patterns.**

A political analyst scrapes department-level results for both rounds to see how support shifted between candidates.

**📰 Verify election reporting.**

A journalist pulls official district counts to fact-check numbers before publishing a story.

**🎓 Build academic datasets.**

A researcher collects province-level results to study turnout and vote share across Peru.

**🛡️ Monitor electoral integrity.**

An election observer scrapes national results to compare against preliminary counts and detect discrepancies.

**📊 Feed dashboards and models.**

A data engineer schedules regular runs to update a live dashboard with the latest official results.

### Why choose this scraper

| | What you get |
|---|---|
| **Official source** | Data comes directly from ONPE, Peru's electoral authority |
| **No API key** | Scrapes the public web portal, no registration or OAuth |
| **Flexible geography** | Get results at national, department, province, or district level |
| **Both rounds** | First and second round of the 2021 general election |
| **Bulk ready** | Export up to a million rows in common formats |

### How it compares

This Actor is the only one on Apify that scrapes official ONPE Peru election results. The competitors below target different sources, so this table shows how they compare on general scraping capabilities.

| Feature | This Actor | 🏯 Tiktok Scraper (Pay Per Result) |
|---|---|---|
| Scrapes ONPE Peru election results | Yes | Not listed |
| Geographic level filtering | Yes | Not listed |
| Election round selection | Yes | Not listed |
| Bulk export up to 1 million rows | Yes | Not listed |
| No API key required | Yes | Not listed |

### Configure the run

Drive the Actor by geographic level and election round, and set a maximum number of results to collect per run. The Input tab lists every parameter.

A first run with the defaults:

```json
{
 "level": "DEPARTAMENTO",
 "round": "P",
 "maxItems": 10
}
```

A larger pull:

```json
{
 "level": "DEPARTAMENTO",
 "round": "P",
 "maxItems": 200
}
```

### Pricing

Pay-per-result: **$0.0085 per result** collected. You pay only for the results written to your dataset.

| Results collected | Approximate cost |
|---|---|
| 100 results | $0.85 |
| 1,000 results | $8.50 |
| 10,000 results | $85.00 |

New Apify accounts start with $5 in free credit.

### Free users

Free-plan runs return up to 10 results as a preview. [Upgrade your Apify plan](https://console.apify.com/sign-up) to collect up to 1,000,000 results per run.

### Run it

1. [Create a free Apify account with $5 in credit](https://console.apify.com/sign-up).
2. Open the [ONPE Peru Elections Results Scraper](https://apify.com/acquistion-automation/onpe-peru-elections-scraper).
3. Set your inputs and any filters, then click **Start**.
4. Export the results as CSV, Excel, JSON, or XML from the **Dataset** tab.

Run it programmatically through the [Apify API](https://docs.apify.com/api/v2) (`run-sync-get-dataset-items`) or the [ApifyClient](https://docs.apify.com/api/client/js) for JavaScript and Python.

### Use with AI agents (MCP)

Give an AI agent live access to ONPE Peru through the Model Context Protocol. Add the Actor to Claude, Cursor, or any MCP client:

```bash
claude mcp add --transport http apify "https://mcp.apify.com?tools=acquistion-automation/onpe-peru-elections-scraper"
```

Then prompt it in plain language to run the scraper and read back the results.

### Troubleshooting

**Why am I getting no results?**

Check that the geographic level and round are valid. Also ensure maxItems is set to at least 1. If the problem persists, the ONPE website may have changed its structure.

**The run is slow or times out.**

Reduce maxItems or choose a higher geographic level like national or department, which returns fewer rows.

**Some fields are empty in the output.**

ONPE may not publish all data for every geographic unit. Empty fields mean the value was not available on the source page.

**I get an error about the website.**

ONPE may be temporarily unavailable. Retry the run later. If the error persists, contact support with the run ID.

### FAQ

| Question | Answer |
|---|---|
| What elections does this Actor cover? | It covers the 2021 Peruvian general election, both the first round (Primera vuelta) and the second round (Segunda vuelta). |
| Which geographic levels can I scrape? | You can choose national, department, province, or district level results. |
| Do I need an API key or login? | No. The Actor reads the public ONPE web portal directly, so no registration or authentication is required. |
| What data does each result include? | Each row includes votes, percentages, and candidate totals for the selected geographic level and round. |
| Can I get both rounds in one run? | No, each run is for one round. Run the Actor twice, once for the first round and once for the second. |
| How many results can I collect? | You can set a maximum of up to one million results per run. |
| What export formats are supported? | You can export to CSV, JSON, Excel, or XML. |
| Is the data official? | Yes, the data comes directly from ONPE, Peru's official electoral authority. |
| Can I filter by candidate? | No, the Actor returns all candidates for the selected geographic level and round. You can filter the output dataset afterwards. |
| Does this Actor work for other elections? | Currently it is configured for the 2021 general election. Contact support if you need other elections. |

🆘 **Need help?** Open an issue in the Issues tab of this Actor with your run ID, your input, and what you expected.

⚠️ **Disclaimer.** This Actor is unofficial and is not affiliated with, endorsed by, or sponsored by Oficina Nacional de Procesos Electorales (ONPE). It collects only publicly available data. You are responsible for using the collected data in compliance with the source's terms of service and applicable data-protection laws, including GDPR, CCPA, and PIPL. Do not use it to collect personal data unlawfully.

# Actor input Schema

## `level` (type: `string`):

Aggregation level for presidential results: national totals or per-department breakdown.

## `maxItems` (type: `integer`):

How many election result rows to collect per run.

## Actor input object example

```json
{
  "level": "DEPARTAMENTO",
  "maxItems": 10
}
```

# Actor output Schema

## `results` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "level": "DEPARTAMENTO",
    "maxItems": 10
};

// Run the Actor and wait for it to finish
const run = await client.actor("acquistion-automation/onpe-peru-elections-scraper").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "level": "DEPARTAMENTO",
    "maxItems": 10,
}

# Run the Actor and wait for it to finish
run = client.actor("acquistion-automation/onpe-peru-elections-scraper").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "level": "DEPARTAMENTO",
  "maxItems": 10
}' |
apify call acquistion-automation/onpe-peru-elections-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,acquistion-automation/onpe-peru-elections-scraper"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/UdmDee8cfzWNHAS0L/builds/8YKvovM8YBp1frsEI/openapi.json
