# nguyenmanhcuong-huster/tool-scrape-blog architecture

> Architecture diagram of the GitHub repository nguyenmanhcuong-huster/tool-scrape-blog, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nguyenmanhcuong-huster/tool-scrape-blog
- Repository: https://github.com/nguyenmanhcuong-huster/tool-scrape-blog

## Overview

##### Project type and purpose
- This is a command-line Python data-processing pipeline that crawls blog URLs, extracts and filters title keywords, checks for duplicates against an existing blog database, and outputs the final set of “main keys” to files (Excel, HTML).
- Key indicators:
- main.py orchestrates the run
- source/crawl_title holds crawling, parsing, filtering, exporting logic
- source/database handles database lookups
- source/download_model fetches any ML or dictionary model

##### High-level file-structure analysis
- Top-level:
– main.py: entry point
– requirements.txt, chromedriver folder: dependencies for Selenium
– database/*.xlsx: reference data
– input.txt / output.xlsx: I/O
- source/:
– download_model/: model/resource downloader
– database/: modules to read/check existing keys
– crawl_title/: the core pipeline steps
- selenium_driver.py (webdriver abstraction)
- crawl_title_from_link.py (URL fetcher)
- filter_title.py (title cleaning)
- extract_key_word.py (keyword candidate extractor)
- translater.py (if needed for i18n)
- excel_handler.py, export_html.py (final output)

##### README architecture insights
- Describes a five-step process:
1. Fetch all blog URLs
2. Extract titles
3. Derive “main key” from each title
4. Check duplicates against timviec365.vn database
5. Export remaining keys

##### Components & interactions
a. Main components:
- Controller: main.py
- Crawler Service: source/crawl_title/selenium_driver.py + crawl_title_from_link.py
- Parser/Extractor: filter_title.py + extract_key_word.py + translater.py
- Storage/DB Layer: source/database/get_title_database.py + database/*.xlsx
- Model Downloader: source/download_model/downloadModel.py
- Exporters: excel_handler.py + export_html.py
- External Systems:
– Target websites (topcv.vn, timviec365.vn)
– ChromeDriver/Chrome headless browser

b. Relationships & data flows:
1. main.py invokes Model Downloader (if needed) → ensures keyword extraction resources
2. main.py starts Crawler Service → retrieves list of post URLs → passes URLs to Parser/Extractor
3. Parser/Extractor cleans titles, extracts key phrases → looks up each key phrase via DB Layer
4. DB Layer queries existing blog database (database/*.xlsx) and timviec365 website
5. Filter out duplicates → hand off to Exporters
6. Exporters write results to output.xlsx and HTML

c. Architectural patterns & principles:
- Pipeline pattern: each module is a stage in the data pipeline
- Single Responsibility per module (crawler vs parser vs exporter)
- Loose coupling: use function calls/imports rather than monolithic scripts
- Clear separation of I/O (database/excel/files) vs business logic

d. Key technologies/frameworks:
- Python 3.x
- Selenium + ChromeDriver (source/crawl_title/selenium_driver.py)
- openpyxl / pandas (likely used in excel_handler.py)
- Custom keyword-extraction logic (extract_key_word.py)
- HTTP client (requests) or Selenium for DB checks

##### Capturing essential details
- Configuration/dependency (requirements.txt, chromedriver) as a supporting block

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Dependencies"
        req["requirements.txt"]:::dependency
        chromedriver["chromedriver.exe"]:::dependency
    end

    main["Controller\nmain.py"]:::internal
    downloadModel["Model Downloader"]:::downloader

    subgraph "Crawler Service"
        seleniumDriver["WebDriver Abstraction"]:::internal
        urlFetcher["URL Fetcher"]:::internal
    end

    subgraph "Parser/Extractor"
        filterTitle["Title Cleaning"]:::internal
        extractKW["Keyword Candidate Extractor"]:::internal
        translator["Translator"]:::internal
    end

    subgraph "Storage/DB Layer"
        dbLookup["DB Lookup Module"]:::internal
        blog1[(blog_list.xlsx)]:::datastore
        blog2[(blog_list_new.xlsx)]:::datastore
    end

    subgraph "Exporters"
        excelExporter["Excel Exporter"]:::exporter
        htmlExporter["HTML Exporter"]:::exporter
    end

    extTopcv["topcv.vn"]:::external
    extTimviec["timviec365.vn"]:::external
    chromeHeadless["Chrome Headless"]:::external

    inputTxt[(input.txt)]:::datastore
    outputXlsx[(output.xlsx)]:::datastore

    req --> main
    chromedriver --> seleniumDriver

    main --> downloadModel
    main --> seleniumDriver
    main --> urlFetcher

    seleniumDriver --> chromeHeadless
    extTopcv --> urlFetcher

    urlFetcher -->|"list of URLs (txt)"| filterTitle
    filterTitle -->|"cleaned titles (JSON)"| extractKW
    extractKW -->|"keywords list (JSON)"| translator
    translator -->|"translated keys (JSON)"| dbLookup

    blog1 --> dbLookup
    blog2 --> dbLookup
    extTimviec --> dbLookup

    dbLookup -->|"filtered keys (JSON)"| excelExporter
    dbLookup -->|"filtered keys (JSON)"| htmlExporter

    excelExporter -->|"Excel file"| outputXlsx
    htmlExporter -->|"HTML file"| outputXlsx

    click main "https://github.com/nguyenmanhcuong-huster/tool-scrape-blog/blob/main/main.py"
    click downloadModel "https://github.com/nguyenmanhcuong-huster/tool-scrape-blog/blob/main/source/download_model/downloadModel.py"
    click seleniumDriver "https://github.com/nguyenmanhcuong-huster/tool-scrape-blog/blob/main/source/crawl_title/selenium_driver.py"
    click urlFetcher "https://github.com/nguyenmanhcuong-huster/tool-scrape-blog/blob/main/source/crawl_title/crawl_title_from_link.py"
    click filterTitle "https://github.com/nguyenmanhcuong-huster/tool-scrape-blog/blob/main/source/crawl_title/filter_title.py"
    click extractKW "https://github.com/nguyenmanhcuong-huster/tool-scrape-blog/blob/main/source/crawl_title/extract_key_word.py"
    click translator "https://github.com/nguyenmanhcuong-huster/tool-scrape-blog/blob/main/source/crawl_title/tranlater.py"
    click dbLookup "https://github.com/nguyenmanhcuong-huster/tool-scrape-blog/blob/main/source/database/get_title_database.py"
    click blog1 "https://github.com/nguyenmanhcuong-huster/tool-scrape-blog/blob/main/database/blog_list.xlsx"
    click blog2 "https://github.com/nguyenmanhcuong-huster/tool-scrape-blog/blob/main/database/blog_list_new.xlsx"
    click excelExporter "https://github.com/nguyenmanhcuong-huster/tool-scrape-blog/blob/main/source/crawl_title/excel_handler.py"
    click htmlExporter "https://github.com/nguyenmanhcuong-huster/tool-scrape-blog/blob/main/source/crawl_title/export_html.py"
    click req "https://github.com/nguyenmanhcuong-huster/tool-scrape-blog/blob/main/requirements.txt"
    click chromedriver "https://github.com/nguyenmanhcuong-huster/tool-scrape-blog/blob/main/chromedriver-win64/chromedriver.exe"
    click inputTxt "https://github.com/nguyenmanhcuong-huster/tool-scrape-blog/blob/main/input.txt"
    click outputXlsx "https://github.com/nguyenmanhcuong-huster/tool-scrape-blog/blob/main/output.xlsx"

    classDef internal fill:#bbdefb,stroke:#1e88e5,color:#0d47a1
    classDef external fill:#c8e6c9,stroke:#2e7d32,color:#1b5e20
    classDef datastore fill:#fff9c4,stroke:#f9a825,color:#f57f17
    classDef exporter fill:#ffe0b2,stroke:#ef6c00,color:#e65100
    classDef downloader fill:#d1c4e9,stroke:#6a1b9a,color:#4a148c
    classDef dependency fill:#eeeeee,stroke:#9e9e9e,color:#424242
```
