Parsing Technical Column Aggregation Pages: Building a Structured Knowledge System
This article explains how to turn technical column aggregation pages into a usable knowledge base. It covers a four-layer pipeline—structure detection, main content extraction, cleaning and normalization, and storage and retrieval—along with practical scoring strategies, metadata design, incremental updates, and common engineering pitfalls to avoid.
1. Why Aggregation Pages Are Hard to Use Directly
Technical column pages are usually not a single article but a content container: navigation and action entry points at the top, the article body in the middle, and recommendations, comments, and copyright notices at the bottom. The page also mixes in interactive button labels such as “Save” and “Activity,” lazy-loaded nodes injected by scripts, ad slots, and analytics tracking. If you save the entire page text as-is, the resulting corpus contains a large amount of noise unrelated to knowledge, which hurts readability and pollutes downstream retrieval and question answering.
So the first principle for handling these pages is not “scraping” but “recognizing intent”: first determine whether the page is an article detail page, a list aggregation page, or an interactive placeholder, then choose an extraction strategy. In engineering terms, it helps to split the flow into four layers: a structure detection layer, a main content extraction layer, a cleaning and normalization layer, and a storage and retrieval layer. The benefit of layering is that each layer can be tested and replaced independently, so a structural change on one site does not force a rewrite of the entire pipeline.
2. Structure Detection: Decide the Page Type Before Extracting
Before parsing, run a lightweight type check. A common approach is to measure text density, link density, and tag depth in candidate body regions. A region with high text density and low link density is usually the main content; a region with dense links and short text is usually navigation or recommendations.
def guess_page_type(html_tree):# Pseudocode: rough classification based on text density and link densitycandidates = html_tree.find_all(block_tags)best = max(candidates, key=lambda n: text_density(n) - link_density(n))if text_density(best) < 0.15:return "list_or_placeholder", bestreturn "article", best
When the page is judged to be a placeholder or a list, do not force main content extraction. Instead, record a “pending” state and wait for rendering to finish, or switch to a structured data API. Only when the page is judged to be an article should you move on to extraction.
3. Main Content Extraction: From Visual Structure to Semantic Boundaries
The key to extraction is finding semantic boundaries rather than relying on fixed selectors. Fixed selectors break easily after a site redesign. A more robust strategy is “candidate scoring plus boundary merging”: compute a score for each block-level node, where the score is a weighted combination of features such as paragraph length, punctuation density, presence of code blocks, and heading level. Then merge adjacent high-scoring nodes into a continuous body and drop isolated short sentences.
def extract_main_text(tree):scored = [(score(node), node) for node in tree.find_all(block_tags)]scored = [(s, n) for s, n in scored if s > THRESHOLD]merged = merge_adjacent(scored) # Merge adjacent high-scoring blocksreturn normalize(merged) # Strip whitespace, unify punctuation
For technical articles that contain code examples, treat code blocks as part of the main content and tag the language separately, so they are not deleted as noise during cleaning. For example:
<article><h2>Summary</h2><p>Body paragraph...</p><pre data-lang="python">def f(): ...</pre></article>
4. Cleaning and Normalization: Turning Noise into Something Ignorable
For the cleaning stage, prefer a whitelist-first approach over a blacklist-first one. Keep the content inside the main container first, then apply fine-grained filtering within it: remove purely interactive text (such as save, share, and activity prompts), remove short lines that repeat, remove lines containing only digits and symbols, and rejoin sentences that were broken by incorrect line wrapping. For Chinese text, also handle mixed full-width and half-width characters, consecutive spaces, and invisible characters.
The goal of normalization is to make one meaning have only one form of expression, which matters especially for later vectorization. If the same passage exists in several whitespace and punctuation variants, retrieval will split it into multiple near-duplicate vectors and reduce recall stability.
5. Storage and Retrieval: Chunking, Vectorization, and Incremental Updates
After cleaning, structure the body into segments: split sections by heading level, then split them into fragments of roughly 300 to 800 characters based on semantic completeness, keeping the heading path between fragments as metadata. Metadata should include at least the page type, section path, code language, crawl time, and content fingerprint.
record = {"title_path": ["Background", "Structure Detection"],"text": "...","lang": "python","fingerprint": sha1(text),"updated_at": now()}
On the retrieval side, use a dual-path strategy of keyword recall plus vector recall, then fuse and rerank the results. Incremental updates rely on the content fingerprint: if the fingerprint is unchanged, skip the fragment; if it changed, rebuild only that fragment’s index instead of paying for a full rebuild. If content is hosted in object storage, keep raw snapshots and parsing results in separate buckets for traceability and auditing. Parsing jobs can be decoupled through a message queue, and monitoring with alerting can track failure rates and latency.
6. Common Pitfalls and Engineering Advice
First, do not treat a page captured before rendering completes as the final result; interactive placeholders will be misread as an empty body. Second, do not over-rely on a single selector; keep multiple fallback strategies. Third, do not delete code blocks and tables during cleaning, since they carry the core information of a technical article. Fourth, always record the content fingerprint and crawl time, otherwise incremental updates and compliance audits are impossible. Fifth, make the parsing pipeline observable: instrument each stage and track candidate counts, filtered counts, and elapsed time, so you can locate the cause quickly when quality drops.
7. Conclusion
Turning aggregation pages into knowledge assets comes down to layering and observability: structure detection decides the entry point, main content extraction decides quality, cleaning and normalization decide consistency, and storage and retrieval decide reuse efficiency. Following this path lets scattered technical content settle into a stable, searchable, continuously updated knowledge system. It can also be combined with general cloud capabilities on Baidu AI Cloud, such as object storage, message queues, logging services, and monitoring with alerting, to form a complete engineering loop.
