# Free eBook Scraper (`epctex/gutenberg-scraper`) Actor

Explore and Download Free eBooks - Find and download a wide selection of free eBooks from Project Gutenberg. Search by keywords and language preferences. Discover literary gems in multiple formats.

- **URL**: https://apify.com/epctex/gutenberg-scraper.md
- **Developed by:** [epctex](https://apify.com/epctex) (community)
- **Categories:** Jobs
- **Stats:** 294 total users, 2 monthly users, 0.0% runs succeeded, 15 bookmarks
- **User rating**: 5.00 out of 5 stars

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

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

## 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

## Actor - Gutenberg.org Scraper

Gutenberg.org Scraper is an [Apify actor](https://apify.com/actors) for extracting data of ebooks from [Gutenberg.org](https://gutenberg.org). It allows you to search for keywords and pick a language. It is build on top of [Apify SDK](https://sdk.apify.com/) and you can run it both on [Apify platform](https://my.apify.com) and locally.

- [Gutenberg.org Scraper Input Parameters](#input-parameters)
- [Gutenberg.org Scraper Input Example](#input-example)
- [Gutenberg.org Scraper Ebook Output](#output)
- [Extend output function](#extend-output-function)
- [Compute Unit Consumption](#compute-unit-consumption)
- [During The Run](#during-the-run)
- [Gutenberg.org Export](#export)

### Gutenberg.org Scraper Input Parameters

The input of this scraper should be JSON containing the list of pages on Gutenberg that should be visited. Possible fields are:

| Field | Type | Description |
| ----- | ---- | ----------- |
| search | String | (optional)  | The keyword that you want to search on Gutenberg |
| language | Array | (optional) List of languages that Gutenberg provides. You can fetch all ebooks of a language with it |
| startUrls | Array | (optional) List of Gutenberg URLs. You should provide ony "search" or "browse" URLs |
| maxItems | Integer | (optional) Maximum number of items that output will contain |
| extendOutputFunction | string | Function that takes a JQuery handle ($) as argument and returns data that will be merged with the default output. More information in [Extend output function](#extend-output-function) |
| proxyConfig | Object | Proxy configuration |

This solution requires the use of **Proxy servers**, either your own proxy servers or you can use <a href="https://www.apify.com/docs/proxy">Apify Proxy</a>.

#### Gutenberg Scraper Input example

```json
{
	"proxyConfig":{"useApifyProxy": true},
	"startUrls":   [
		{ "url": "https://www.gutenberg.org/browse/recent/last7" },
    { "url": "https://www.gutenberg.org/browse/titles/h" }
	]
}

```

### Gutenberg Ebook Output

The structure of each item in Gutenberg ebooks looks like this:

```json
{
  "author": "United States. National Park Service",
  "title": "Cumberland Island: Junior Ranger Program Activity Guide for Ages 5-7",
  "language": "English",
  "htmlURL": "https://www.gutenberg.org/files/61452/61452-h/61452-h.htm",
  "epubURL": "https://www.gutenberg.org/ebooks/61452.epub.images?session_id=24e44a13d40847bb8d8b13a9216689880a3221cf",
  "kindleURL": "https://www.gutenberg.org/ebooks/61452.kindle.images?session_id=24e44a13d40847bb8d8b13a9216689880a3221cf",
  "plainTextURL": "https://www.gutenberg.org/files/61452/61452-0.txt"
}
```

#### Extend output function

You can use this function to update the default output of this actor. This function gets a JQuery handle `$` as an argument so you can choose what data from the page you want to scrape. The output from this will function will get merged with the default output.

The return value of this function has to be an object!

You can return fields to achive 3 different things:

- Add a new field - Return object with a field that is not in the default output
- Change a field - Return an existing field with a new value
- Remove a field - Return an existing field with a value `undefined`

#### Compute Unit Consumption

The actor optimized to run blazing fast and scrape many product as possible. Therefore, it forefronts all product detail requests. If actor doesn't block very often it'll scrape ~250 products in 3 minutes with 0.0235 compute units.

### During the Run

During the run, the actor will output messages letting you know what is going on. Each message always contains a short label specifying which page from the provided list is currently specified.
When items are loaded from the page, you should see a message about this event with a loaded item count and total item count for each page.

If you provide incorrect input to the actor, it will immediately stop with failure state and output an explanation of what is wrong.

### Gutenberg Export

During the run, the actor stores results into a dataset. Each item is a separate item in the dataset.

You can manage the results in any languague (Python, PHP, Node JS/NPM). See the FAQ or <a href="https://www.apify.com/docs/api" target="blank">our API reference</a> to learn more about getting results from this Gutenberg actor.

### Contact

Please visit us through [epctex.com](https://epctex.com) to see all the products that is available for you. If you are looking for any custom integration or so, please reach out to us through the chat box in [epctex.com](https://epctex.com). In need of support? <devops@epctex.com> is at your service.

# Actor input Schema

## `search` (type: `string`):

Keyword that you want to search in Gutenberg.org

## `language` (type: `string`):

Select a language that Gutenberg.org provides

## `startUrls` (type: `array`):

URLs to start with. It should be category or product detail URLs

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

Maximum number of items you want on your results

## `extendOutputFunction` (type: `string`):

Function that takes a JQuery handle ($) as argument and returns data that will be merged with the default output

## `proxyConfig` (type: `object`):

Select proxies to be used by your crawler.

## Actor input object example

```json
{
  "search": "book",
  "language": "none",
  "startUrls": [
    {
      "url": "https://www.gutenberg.org/browse/recent/last7"
    },
    {
      "url": "https://www.gutenberg.org/browse/titles/h"
    }
  ],
  "maxItems": 5,
  "extendOutputFunction": "($) => { return {} }",
  "proxyConfig": {
    "useApifyProxy": true
  }
}
```

# 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 = {
    "search": "book",
    "startUrls": [
        {
            "url": "https://www.gutenberg.org/browse/recent/last7"
        },
        {
            "url": "https://www.gutenberg.org/browse/titles/h"
        }
    ],
    "maxItems": 5,
    "extendOutputFunction": ($) => { return {} },
    "proxyConfig": {
        "useApifyProxy": true
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("epctex/gutenberg-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 = {
    "search": "book",
    "startUrls": [
        { "url": "https://www.gutenberg.org/browse/recent/last7" },
        { "url": "https://www.gutenberg.org/browse/titles/h" },
    ],
    "maxItems": 5,
    "extendOutputFunction": "($) => { return {} }",
    "proxyConfig": { "useApifyProxy": True },
}

# Run the Actor and wait for it to finish
run = client.actor("epctex/gutenberg-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 '{
  "search": "book",
  "startUrls": [
    {
      "url": "https://www.gutenberg.org/browse/recent/last7"
    },
    {
      "url": "https://www.gutenberg.org/browse/titles/h"
    }
  ],
  "maxItems": 5,
  "extendOutputFunction": "($) => { return {} }",
  "proxyConfig": {
    "useApifyProxy": true
  }
}' |
apify call epctex/gutenberg-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,epctex/gutenberg-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/ac62voxbGThzhprWs/builds/KggHC62dRtjAuwJ6A/openapi.json
