How to Build a High‑Performance Novel Site Crawler with MongoDB and Multithreading

This article walks through building a high‑performance novel‑site crawler using MongoDB, detailing the extraction of category links, multi‑process/thread URL management, database operations, and the final deduplication results, while illustrating each step with diagrams and screenshots.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Build a High‑Performance Novel Site Crawler with MongoDB and Multithreading

Inspired by a tutorial on crawling a top novel site, the author decided to crawl the "Yisou" novel website using MongoDB instead of MySQL.

First, the overall code framework is shown.

The crawler starts by extracting every category link from the ranking page, then follows each link to crawl the content. The all_theme file is examined first.

The running result shows the book category.

From this, the crawler constructs all page‑link URLs for each category, creating the entry points for the spider – over 5,000 pages in total.

Database operations are encapsulated to support multiprocessing and multithreading. Each process must know which URLs have been crawled and which remain. Two status flags are defined for every URL:

outstanding – waiting to be crawled

processing – currently being crawled

complete – crawl finished

The state transitions are simple: all initial URLs are marked outstanding ; when crawling starts, the status changes to processing ; upon success it becomes complete ; failed URLs revert to outstanding . A timer resets stalled URLs back to outstanding after a timeout.

The main crawler program is then presented.

Running the crawler yields many duplicate entries; after deduplication, only a few hundred thousand unique books remain, which the author finds disappointing.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

multithreadingData ExtractionMongoDBScraping
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.