metascraper

microlinkhqMIT活跃维护

从任意 URL 抓取网页元数据,自动解析 Open Graph、JSON-LD 和 HTML meta 标签,并带智能兜底,适合做链接预览和内容摘要。

Scrape metadata from any URL using Open Graph, JSON-LD, HTML meta tags, and smart fallbacks.

v5.58.6发布于 2026-11-08 16:10 UTC2,754star +2 / 7 天183fork同步于 2026-11-10 11:43 UTC

怎么上手

由 README 提炼,执行前请确认
npm install metascraper metascraper-author metascraper-date metascraper-description metascraper-image metascraper-logo metascraper-publisher metascraper-title metascraper-url
硬件要求按 README 说明

纯 Node.js 库,README 未说明硬件要求;若用 html-get 配合 browserless 获取渲染后 HTML,则需本地运行 Chromium

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

从任意 URL 的 HTML 中按优先级规则提取统一元数据,省去自己写解析逻辑

从任意 URL 抓取网页元数据,自动解析 Open Graph、JSON-LD 和 HTML meta 标签,并带智能兜底,适合做链接预览和内容摘要。

核心能力

  • 按 Open Graph、JSON-LD、Twitter Cards、Microdata、RDFa 等多来源提取
  • 规则按优先级从具体到通用依次回退,首个命中即停止
  • 按属性拆成独立规则包,只装需要的字段
  • 支持自定义规则包覆盖或扩展默认提取逻辑
  • 可传入 html、url、htmlDom 等选项控制输入与输出字段

容易踩的坑

metascraper 本身不抓网页,需自行提供目标 URL 的 HTML,README 推荐用 html-get 配合 browserless 获取渲染后 HTML;规则包要按需单独安装并在初始化时按顺序传入,顺序影响最终取值;需要渲染后 HTML 时依赖无头浏览器,规模化运行需自行处理代理与反爬

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v5.58.6
  1. v5.58.6最新正式版2026-11-08 · 2026-11-08 16:10 UTC

    5.58.6 (2026-11-08)

    Bug Fixes

    • metascraper: log rule values without a string form (#890) (0566137)
  2. v5.58.52026-10-15 · 2026-10-15 07:54 UTC
    查看更新说明

    5.58.5 (2026-10-15)

    Bug Fixes

    • metascraper-author: make strict guard await its rule (#888) (c1188fc), closes #887
  3. v5.58.42026-10-09 · 2026-10-09 16:33 UTC
    查看更新说明

    5.58.4 (2026-10-09)

    Note: Version bump only for package metascraper

  4. v5.58.32026-09-18 · 2026-09-18 18:30 UTC
    查看更新说明

    5.58.3 (2026-09-18)

    Bug Fixes

    • metascraper-tiktok: read rehydration JSON (#885) (1ce9525)
  5. v5.58.22026-09-17 · 2026-09-17 20:35 UTC
    查看更新说明

    5.58.2 (2026-09-17)

    Bug Fixes

    • metascraper-instagram: prefer larger post image (#883) (f994913)

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    A library to easily extract unified metadata from websites using Open Graph, Microdata, RDFa, Twitter Cards, JSON-LD, HTML, and more.


    What is it

    The metascraper library allows you to easily scrape metadata from an article on the web using Open Graph metadata, regular HTML metadata, and a series of fallbacks.

    It follows a few principles:

    • Ensure a high accuracy for online articles by default.
    • Make it simple to add new rules or override existing ones.
    • Don't restrict rules to CSS selectors or text accessors.

    Getting started

    Below is a real example of extracting metadata from a live website. The same logic shown here is running online and can be tested directly at microlink.io/meta:

    metascraper requires two inputs: The target URL and the HTML markup behind that URL.

    There are multiple ways to retrieve the HTML markup, but it needs to be as accurate as possible.

    For that reason, we developed html-get, which uses a headless browser to retrieve HTML in a way that works seamlessly with metascraper.

    const getHTML = require('html-get')
    
    /**
     * `browserless` will be passed to `html-get`
     * as driver for getting the rendered HTML.
     */
    const browserless = require('browserless')()
    
    const getContent = async url => {
      // create a browser context inside the main Chromium process
      const browserContext = browserless.createContext()
      const promise = getHTML(url, { getBrowserless: () => browserContext })
      // close browser resources before return the result
      promise.then(() => browserContext).then(browser => browser.destroyContext())
      return promise
    }
    
    /**
     * `metascraper` is a collection of tiny packages,
     * so you can just use what you actually need.
     */
    const metascraper = require('metascraper')([
      require('metascraper-author')(),
      require('metascraper-date')(),
      require('metascraper-description')(),
      require('metascraper-image')(),
      require('metascraper-logo')(),
      require('metascraper-publisher')(),
      require('metascraper-title')(),
      require('metascraper-url')()
    ])
    
    /**
     * The main logic
     */
    getContent('https://microlink.io')
      .then(metascraper)
      .then(metadata => console.log(metadata))
      .then(browserless.close)
      .then(process.exit)
    

    The output will be something like:

    {
      "author": "Microlink HQ",
      "date": "2022-07-10T22:53:04.856Z",
      "description": "Enter a URL, receive information. Normalize metadata. Get HTML markup. Take a screenshot. Identify tech stack. Generate a PDF. Automate web scraping. Run Lighthouse",
      "image": "https://cdn.microlink.io/logo/banner.jpeg",
      "logo": "https://cdn.microlink.io/logo/logo.png",
      "publisher": "Microlink",
      "title": "Turns websites into data — Microlink",
      "url": "https://microlink.io/"
    }
    

    What data it detects

    Note: Custom metadata detection can be defined using a rule bundle.

    Here is an example of the metadata that metascraper can detect:

    • audio — e.g. https://cf-media.sndcdn.com/U78RIfDPV6ok.128.mp3 A audio URL that best represents the article.

    • author — e.g. Noah Kulwin A human-readable representation of the author's name.

    • date — e.g. 2016-05-27T00:00:00.000Z An ISO 8601 representation of the date the article was published.

    • description — e.g. Venture capitalists are raising money at the fastest rate... The publisher's chosen description of the article.

    • video — e.g. https://assets.entrepreneur.com/content/preview.mp4 A video URL that best represents the article.

    • image — e.g. https://assets.entrepreneur.com/content/3x2/1300/20160504155601-GettyImages-174457162.jpeg An image URL that best represents the article.

    • lang — e.g. en An ISO 639-1 representation of the url content language.

    • logo — e.g. https://entrepreneur.com/favicon180x180.png An image URL that best represents the publisher brand.

    • publisher — e.g. Fast Company A human-readable representation of the publisher's name.

    • title — e.g. Meet Wall Street's New A.I. Sheriffs The publisher's chosen title of the article.

    • url — e.g. http://motherboard.vice.com/read/google-wins-trial-against-oracle-saves-9-billion The URL of the article.

    The cloud API solution

    Running this at scale means operating headless browsers, proxies, and antibot workarounds.

    If you don’t want to manage that infrastructure, you can use the fully managed Microlink API.

    It automatically handles proxy rotation, paywalls, bot detection, and restricted platforms such as major social networks, while scaling on demand.

    Pricing is pay-as-you-go and starts for free.

    How it works

    metascraper is built out of rules bundles.

    It is designed to be extensible. You can compose your own transformation pipeline using existing rules or create your own.

    Rule bundles are collections of HTML selectors targeting a specific property. When you load the library, it implicitly loads the core rules.

    Each set of rules loads a set of selectors to extract a specific value.

    Rules are ordered by priority. The first rule to successfully resolve the value stops the process. The order goes from most specific to most generic.

    Rules work as fallbacks for one another:

    • If the first rule fails, then it falls back on the second rule.
    • If the second rule fails, it is time for the third rule.
    • Etc.

    metascraper does this until it finishes all the rules or finds the first rule that resolves the value.

    Importing rules

    metascraper exports a constructor that need to be initialized providing a collection of rules to load:

    const metascraper = require('metascraper')([
      require('metascraper-author')(),
      require('metascraper-date')(),
      require('metascraper-description')(),
      require('metascraper-image')(),
      require('metascraper-logo')(),
      require('metascraper-publisher')(),
      require('metascraper-title')(),
      require('metascraper-url')()
    ])
    

    Again, the order of rules are loaded are important: Just the first rule that resolve the value will be applied.

    Use the first parameter to pass custom options specific per each rules bundle:

    const metascraper = require('metascraper')([
      require('metascraper-logo')({
        filter: url => url.endsWith('.png')
      })
    ])
    

    Rules bundles

    ?> Can't find the rules bundle that you want? Let's open an issue to create it.

    Official

    Rules bundles maintained by metascraper maintainers.

    Core essential

    Vendor specific

    Community

    Rules bundles maintained by individual users.

    See CONTRIBUTING to add your own module!

    API

    constructor(rules)

    Create a new metascraper instance declaring the rules bundle to be used explicitly.

    rules

    Type: Array

    The collection of rules bundle to be loaded.

    metascraper(options)

    Call the instance for extracting content based on rules bundle provided at the constructor.

    options
    html

    Type: String

    The HTML markup for extracting the content.

    htmlDom

    Type: object

    The DOM representation of the HTML markup. When it's not provided, it's get from the html parameter.

    omitPropNames

    Type: Set Default: []

    A set of property names that should be omitted. When specified, these properties will be missing in the returned metadata objects, and rules related to that will not be computed.

    pickPropNames

    Type: Set Default: undefined

    A set of property names to pick for the metadata extraction process. When specified, only rules for these properties will be executed, and all other properties will be omitted. Takes precedence over omitPropNames when both are specified.

    rules

    Type: Array

    You can pass additional rules to add on execution time.

    These rules will be merged with your loaded rules at the beginning.

    url

    Required Type: String

    The URL associated with the HTML markup.

    It is used for resolve relative links that can be present in the HTML markup.

    it can be used as fallback field for different rules as well.

    validateUrl

    Type: boolean Default: true

    Ensure the URL provided is validated as a WHATWG URL API compliant.

    const metascraper = require('metascraper')([
      require('metascraper-title')(),
      require('metascraper-image')(),
      require('metascraper-description')()
    ])
    
    const html = '<title>Example</title><meta property="og:image" content="image.jpg">'
    const url = 'https://example.com'
    
    // Omit the image property
    const omitPropNames = new Set(['image'])
    const metadata = await metascraper({ url, html, omitPropNames })
    
    console.log(metadata)
    // Output: { title: 'Example', image: null, description: null }
    

    Environment Variables

    METASCRAPER_RE2

    Type: boolean Default: true

    It attemptt to load re2 to use instead of RegExp.

    Benchmark

    To demonstrate metascraper's exceptional accuracy, here is how it outperforms similar libraries:

    Librarymetascraperhtml-metadatanode-metainspectoropen-graph-scraperunfluff
    Correct95.54%74.56%61.16%66.52%70.90%
    Incorrect1.79%1.79%0.89%6.70%10.27%
    Missed2.68%23.67%37.95%26.34%8.95%

    A big part of the reason for metascraper's higher accuracy is that it relies on a series of fallbacks for each piece of metadata, instead of just looking for the most commonly-used, spec-compliant pieces of metadata, like Open Graph.

    metascraper's default settings are targetted specifically at parsing online articles, which is why it's able to be more highly-tuned than the other libraries for that purpose.

    If you're interested in the breakdown by individual pieces of metadata, check out the full comparison summary, or dive into the raw result data for each library.

    License

    metascraper © Microlink, released under the MIT License. Authored and maintained by Microlink with help from contributors.

    microlink.io · GitHub microlinkhq · X @microlinkhq