Grab MTG story articles and generate EPUB files from them.
To generate the EPUB, this script does some aggressive web scraping, removing elements that are not part of the story article. The logic is very specific to the current MTG story website layout, so this script will not work for other websites and will need to be updated whenever WOTC changes the website.
You can combine all chapters by calling the combine script!
Last updated: 2025-07-18 (Edge of Eternities)
- Node.js: Ensure you have Node.js installed on your computer. You can download it from the Node.js official site.
- Dependencies: The script uses these Node.js packages: • axios for making HTTP requests. • cheerio for HTML parsing and manipulation. • EPUB-gen for generating EPUB files.
To install these dependencies, navigate to the script folder in your terminal and run the following command:
npm install
Use this command in your terminal to run the script. Pass the chapter URLs as arguments:
node generateEpub.js <url1> <url2> ...
Replace , , etc., with the actual URLs you want to convert into EPUB files. For example:
node generateEpub.js https://example.com/article1 https://example.com/article2
The script will generate EPUB files for each URL provided in the command line arguments.
Files will be saved in a folder called downloads with names based on the article titles (spaces replaced with underscores).
You can combine EPUB files by using the script in combine.js.
node combine.js path/to/folder outputName.EPUB
This script automatically removes the Table of Contents of each chapter and creates a new ToC for the new file.
The output will be saved in a folder called combined.
- The script expects the article’s content to be inside an HTML element with the ID
#article-body. If the website structure differs, you may need to modify this line:
const contentElement = $('#article-body');
Replace #article-body with the appropriate selector if needed.
-
Ensure the URLs you pass are publicly accessible and the website does not block web scraping.
-
Currently, the script ignores images, maybe in the future I will add support.
This script is meant to be a quick and dirty way to grab the story articles and send them to my kindle. It is in no way meant to be a definitive and polished piece of code, just something to help my lazy ass read the story :D