@decodo/sdk-ts

中文文档
3.0.0发布于 2026/10/30MITTypeScriptESM + CJS构建来源已验证近 30 天下载 9008

Decodo API 的官方类型SDK脚本

中文使用文档
文档目录21 节
  1. 所需资源
  2. 安装
  3. 快开始
  4. 配置
  5. 网络搜索 API
  6. 同步刮擦
  7. Async 刮伤
  8. 批发
  9. 搜索
  10. 地图
  11. 爬行
  12. 支助目标
  13. 搜索引擎
  14. 电子商务
  15. 社交媒体
  16. AI 工具
  17. 普遍刮去
  18. 处理错误
  19. 相关寄存器
  20. 开始吧
  21. 许可证

解码器类型SDK

Node.js License

Decodo Web Scraping API的官方TypeScript SDK版本.

为搜索引擎,eCommerce平台,社交媒体,AI工具等建立强大的打出刮取工作流程,并多使用Decodo Web Scraping API.

  • 用 IDE 自动完成完整输入的目标和参数
  • 同步、同步和分批刮取方法
  • 土著 fetch 支持,节点.js 18+
  • 为更安全的整合而打入的错误等级
  • 为 TypeScript 和现代 JavaScript 运行时间所建

什么是Decodo TypeScript SDK? (英语)?

Decodo TypeScript SDK是Decodo Web Craping API的官方TypeScript SDK. 它为与Google,Amazon,TikTok,Reddit,YouTube,ChatGPT,Perflexity等Decodo目标互动提供了打入的界面.

与其手动构建HTTP请求并验证有效载荷,不如直接在编辑器中使用完全打入的方法和特定目标参数来工作.

为什么用SDK?

  • 强打字和自动完成。目标参数已全部输入,以便更好的DX和更少的错误.
  • 统一刮取接口通过一个SDK与搜索引擎、eCommerce平台、社交媒体和AI工具合作.
  • Async和分批工作流程。创建刮取任务、民意调查状态和分批处理.
  • 输入错误. 安全处理认证、验证、超时和限速故障.
  • 最小设置本地用途 fetch,不需要额外的HTTP客户端.

所需资源

  • 节点.js 18+(用于本地 fetch(中文(简体) )
  • TypeScript 5.0+ (推荐用于最佳类型推论)

安装

npm install --save @decodo/sdk-ts

快开始

创建新工程 :

mkdir scrape-with-decodo
cd scrape-with-decodo

npm init -y
npm install --save @decodo/sdk-ts

touch main.js
可选:防止模块类型警告 运行以下脚本以切换到无害环境管理模块:
node -e "let p=require('./package.json'); p.type='module'; require('fs').writeFileSync('./package.json', JSON.stringify(p, null, 2))"

从您的 Web Data API 订阅中复制您的 Web Data API 密钥 Decodo 仪表板 并用在下面的例子中。 旧计划只有基本的验证符,您可以通过它 token 相反(见 配置) (中文(简体) ).

// main.js
import { DecodoClient, Target } from '@decodo/sdk-ts';

const client = new DecodoClient({
  webScrapingApi: {
    apiKey: '<api_key>',
  },
});

const result = await client.webScrapingApi.scrape({
  target: Target.GoogleSearch,
  query: 'coffee shops',
  geo: 'United States',
  parse: true,
});
console.log(JSON.stringify(result, null, 2));

运行脚本 :

node main.js
示例响应
{
  "results": [
    {
      "content": {
        "results": {
          "last_visible_page": 10,
          "page": 1,
          "parse_status_code": 12000,
          "results": {
            "local_pack": [
              {
                "items": [
                  {
                    "address": "Rochester, NY",
                    "paid": false,
                    "pos": 1,
                    "rating": 4.9,
                    "rating_count": 1700,
                    "subtitle": "Coffee shop",
                    "title": "Albunn Coffee House"
                  },
                  {
                    "address": "Rochester, NY",
                    "paid": false,
                    "pos": 2,
                    "rating": 4.8,
                    "rating_count": 937,
                    "subtitle": "Coffee shop",
                    "title": "Layali Coffee House"
                  },
                  {
                    "address": "Ocean Township, NJ",
                    "paid": false,
                    "pos": 3,
                    "rating": 4.9,
                    "rating_count": 124,
                    "subtitle": "Coffee shop",
                    "title": "Ocean Brew Co."
                  }
                ],
                "pos_overall": 1
              }
            ],
            "navigation": [
              {
                "pos": 1,
                "title": "AI Mode",
                "url": "/search?q=coffee+shops&sca_esv=525e608177515078&hl=en&gl=us&udm=50&fbs=ADc_l-aN0CWEZBOHjofHoaMMDiKp9lEhFAN_4ain3HSNQWw-mOdEry7qMdvK9DVYTQhhmGPzdLibceP-axzNRyypn83aa9v77RK3nAyJbS7Ww3c5hEZ41MHuBwA1cj9fLdcvZl39JyX99GA6dTRuy8597fUa5gVhW6ji9TQaHsuXH4CUtx2nUSCgjR6EycjMi9JpkD60fmHj94qqvvZFpMtWVwcBzf9XLw&aep=1&ntc=1&sa=X&ved=2ahUKEwiq0P6Xv8yUAxUPNvsDHaaIEQsQ2J8OegQIEhAD"
              },
              {
                "pos": 2,
                "title": "All"
              },
              {
                "pos": 3,
                "title": "Shopping",
                "url": "/search?sca_esv=525e608177515078&hl=en&gl=us&udm=28&fbs=ADc_l-aN0CWEZBOHjofHoaMMDiKp9lEhFAN_4ain3HSNQWw-mOdEry7qMdvK9DVYTQhhmGPzdLibceP-axzNRyypn83aa9v77RK3nAyJbS7Ww3c5hEZ41MHuBwA1cj9fLdcvZl39JyX99GA6dTRuy8597fUa5gVhW6ji9TQaHsuXH4CUtx2nUSCgjR6EycjMi9JpkD60fmHj94qqvvZFpMtWVwcBzf9XLw&q=coffee+shops&ved=1t:220175&ictx=111"
              },
              {
                "pos": 4,
                "title": "Maps",
                "url": "https://maps.google.com/maps?sca_esv=525e608177515078&hl=en&gl=us&output=search&q=coffee+shops&source=lnms&fbs=ADc_l-aN0CWEZBOHjofHoaMMDiKp9lEhFAN_4ain3HSNQWw-mOdEry7qMdvK9DVYTQhhmGPzdLibceP-axzNRyypn83aa9v77RK3nAyJbS7Ww3c5hEZ41MHuBwA1cj9fLdcvZl39JyX99GA6dTRuy8597fUa5gVhW6ji9TQaHsuXH4CUtx2nUSCgjR6EycjMi9JpkD60fmHj94qqvvZFpMtWVwcBzf9XLw&entry=mc&ved=1t:200715&ictx=111"
              },
              {
                "pos": 5,
                "title": "Images",
                "url": "/search?sca_esv=525e608177515078&hl=en&gl=us&udm=2&fbs=ADc_l-aN0CWEZBOHjofHoaMMDiKp9lEhFAN_4ain3HSNQWw-mOdEry7qMdvK9DVYTQhhmGPzdLibceP-axzNRyypn83aa9v77RK3nAyJbS7Ww3c5hEZ41MHuBwA1cj9fLdcvZl39JyX99GA6dTRuy8597fUa5gVhW6ji9TQaHsuXH4CUtx2nUSCgjR6EycjMi9JpkD60fmHj94qqvvZFpMtWVwcBzf9XLw&q=coffee+shops&sa=X&ved=2ahUKEwiq0P6Xv8yUAxUPNvsDHaaIEQsQtKgLegQIFhAB"
              },
              {
                "pos": 6,
                "title": "Short videos",
                "url": "/search?sca_esv=525e608177515078&hl=en&gl=us&udm=39&fbs=ADc_l-aN0CWEZBOHjofHoaMMDiKp9lEhFAN_4ain3HSNQWw-mOdEry7qMdvK9DVYTQhhmGPzdLibceP-axzNRyypn83aa9v77RK3nAyJbS7Ww3c5hEZ41MHuBwA1cj9fLdcvZl39JyX99GA6dTRuy8597fUa5gVhW6ji9TQaHsuXH4CUtx2nUSCgjR6EycjMi9JpkD60fmHj94qqvvZFpMtWVwcBzf9XLw&q=coffee+shops&sa=X&ved=2ahUKEwiq0P6Xv8yUAxUPNvsDHaaIEQsQs6gLegQIFxAB"
              },
              {
                "pos": 7,
                "title": "Videos",
                "url": "/search?sca_esv=525e608177515078&hl=en&gl=us&udm=7&fbs=ADc_l-aN0CWEZBOHjofHoaMMDiKp9lEhFAN_4ain3HSNQWw-mOdEry7qMdvK9DVYTQhhmGPzdLibceP-axzNRyypn83aa9v77RK3nAyJbS7Ww3c5hEZ41MHuBwA1cj9fLdcvZl39JyX99GA6dTRuy8597fUa5gVhW6ji9TQaHsuXH4CUtx2nUSCgjR6EycjMi9JpkD60fmHj94qqvvZFpMtWVwcBzf9XLw&q=coffee+shops&sa=X&ved=2ahUKEwiq0P6Xv8yUAxUPNvsDHaaIEQsQtKgLegQIGBAB"
              },
              {
                "pos": 8,
                "title": "Forums",
                "url": "/search?sca_esv=525e608177515078&hl=en&gl=us&udm=18&fbs=ADc_l-aN0CWEZBOHjofHoaMMDiKp9lEhFAN_4ain3HSNQWw-mOdEry7qMdvK9DVYTQhhmGPzdLibceP-axzNRyypn83aa9v77RK3nAyJbS7Ww3c5hEZ41MHuBwA1cj9fLdcvZl39JyX99GA6dTRuy8597fUa5gVhW6ji9TQaHsuXH4CUtx2nUSCgjR6EycjMi9JpkD60fmHj94qqvvZFpMtWVwcBzf9XLw&q=coffee+shops&sa=X&ved=2ahUKEwiq0P6Xv8yUAxUPNvsDHaaIEQsQs6gLegUIuQEQAQ"
              },
              {
                "pos": 9,
                "title": "News",
                "url": "/search?sca_esv=525e608177515078&hl=en&gl=us&q=coffee+shops&tbm=nws&source=lnms&fbs=ADc_l-aN0CWEZBOHjofHoaMMDiKp9lEhFAN_4ain3HSNQWw-mOdEry7qMdvK9DVYTQhhmGPzdLibceP-axzNRyypn83aa9v77RK3nAyJbS7Ww3c5hEZ41MHuBwA1cj9fLdcvZl39JyX99GA6dTRuy8597fUa5gVhW6ji9TQaHsuXH4CUtx2nUSCgjR6EycjMi9JpkD60fmHj94qqvvZFpMtWVwcBzf9XLw&sa=X&ved=2ahUKEwiq0P6Xv8yUAxUPNvsDHaaIEQsQ0pQJegUItwEQAQ"
              },
              {
                "pos": 10,
                "title": "Web",
                "url": "/search?sca_esv=525e608177515078&hl=en&gl=us&udm=web&fbs=ADc_l-aN0CWEZBOHjofHoaMMDiKp9lEhFAN_4ain3HSNQWw-mOdEry7qMdvK9DVYTQhhmGPzdLibceP-axzNRyypn83aa9v77RK3nAyJbS7Ww3c5hEZ41MHuBwA1cj9fLdcvZl39JyX99GA6dTRuy8597fUa5gVhW6ji9TQaHsuXH4CUtx2nUSCgjR6EycjMi9JpkD60fmHj94qqvvZFpMtWVwcBzf9XLw&q=coffee+shops&sa=X&ved=2ahUKEwiq0P6Xv8yUAxUPNvsDHaaIEQsQs6gLegUIugEQAQ"
              },
              {
                "pos": 11,
                "title": "Books",
                "url": "/search?sca_esv=525e608177515078&hl=en&gl=us&q=coffee+shops&udm=36&source=lnms&fbs=ADc_l-aN0CWEZBOHjofHoaMMDiKp9lEhFAN_4ain3HSNQWw-mOdEry7qMdvK9DVYTQhhmGPzdLibceP-axzNRyypn83aa9v77RK3nAyJbS7Ww3c5hEZ41MHuBwA1cj9fLdcvZl39JyX99GA6dTRuy8597fUa5gVhW6ji9TQaHsuXH4CUtx2nUSCgjR6EycjMi9JpkD60fmHj94qqvvZFpMtWVwcBzf9XLw&sa=X&ved=2ahUKEwiq0P6Xv8yUAxUPNvsDHaaIEQsQ0pQJegUIuAEQAQ"
              }
            ],
            "organic": [
              {
                "desc": "For an alternate, local view, Eater has an interesting list of what it considers Philadelphia's 21 Essential Coffee Shops. Header image: Penn's Landing and ...Read more",
                "favicon_text": "Brian's Coffee Spot",
                "pos": 1,
                "pos_overall": 2,
                "title": "Philadelphia",
                "url": "https://www.brian-coffee-spot.com/the-coffee-spot-guide-to/usa-canada/philadelphia/",
                "url_shown": "https://www.brian-coffee-spot.com› usa-canada › phila..."
              },
              {
                "desc": "Which Pittsburgh coffee shops are worth your time? Our ever-expanding guide gets to the bottom of that question.Read more",
                "favicon_text": "Discover the Burgh",
                "pos": 2,
                "pos_overall": 3,
                "title": "48 Pittsburgh Coffee Shops to Grab a Delicious Brew",
                "url": "https://www.discovertheburgh.com/pittsburgh-coffee-shops/",
                "url_shown": "https://www.discovertheburgh.com› ... › Coffee"
              },
              {
                "desc": "Sep 29, 2016 — Best Coffee Shops in Atlanta · Octane · Dancing Goats Coffee Bar · Chrome Yellow Trading Co. · Revelator Coffee Company. Brash isn't the only ...Read more",
                "favicon_text": "ATL Bucket List",
                "pos": 3,
                "pos_overall": 4,
                "title": "Best Coffee Shops in Atlanta",
                "url": "https://www.atlbucketlist.com/2016/09/29/best-coffee-shops-in-atlanta/",
                "url_shown": "https://www.atlbucketlist.com› Food & Drink"
              },
              {
                "desc": "Atticus Coffee & Gifts (222 N Howard St, Spokane, WA // 509.747.0336) There is a lot to love about downtown's Atticus. Firstly, it's one of the most ...Read more",
                "favicon_text": "Spokane Eats",
                "pos": 4,
                "pos_overall": 6,
                "title": "BEST COFFEE IN SPOKANE",
                "url": "https://spokaneeats.net/best-coffee-in-spokane/",
                "url_shown": "https://spokaneeats.net› Blog"
              },
              {
                "desc": "Tucson has many excellent coffee shops including Exo Roast Co., Ren Coffeehouse, Presta Coffee Roasters and Ombre Coffee.",
                "favicon_text": "Globalphile",
                "pos": 5,
                "pos_overall": 7,
                "title": "The Best Coffee Shops in Tucson, AZ",
                "url": "https://globalphile.com/the-best-coffee-shops-in-tucson-az/",
                "url_shown": "https://globalphile.com› the-best-coffee-shops-in-tucson..."
              },
              {
                "desc": "Oct 30, 2025 — The Best Coffee Shops in Orange County, California: A Local's Guide · Brot Coffee Co. · Daydream Surf Shop – Newport Beach · Hidden House Coffee ...Read more",
                "favicon_text": "Lauren Belzer",
                "pos": 6,
                "pos_overall": 8,
                "title": "The Best Coffee Shops in Orange County, California",
                "url": "https://laurenbelz.com/best-coffee-orange-county/",
                "url_shown": "https://laurenbelz.com› best-coffee-orange-county"
              },
              {
                "desc": "Sep 11, 2024 — Writer Gene Kahane names his top five favorite local coffee shops around the island of Alameda, including LazyBird and The Local.",
                "favicon_text": "Alameda Post",
                "pos": 7,
                "pos_overall": 9,
                "title": "Five Favorite Coffee Shops",
                "url": "https://alamedapost.com/features/alameda-life/five-favorite-coffee-shops/",
                "url_shown": "https://alamedapost.com› Features › Alameda Life"
              },
              {
                "desc": "Jun 24, 2025 — 1. Royal Flamingo Coffee -> I Like It Like That · 2. Roosevelt Coffeehouse -> Olentangy River Brewing Company · 3. Ravello's Coffee -> The Daily ...Read more",
                "favicon_text": "Breakfast With Nick",
                "pos": 8,
                "pos_overall": 10,
                "title": "Columbus' Best Coffee Shops in Bars",
                "url": "https://breakfastwithnick.com/2025/06/24/the-best-coffee-shops-in-bars-columbus-ohio/",
                "url_shown": "https://breakfastwithnick.com› 2025/06/24 › the-best-c..."
              }
            ],
            "paid": [],
            "related_searches": [
              {
                "pos_overall": 11,
                "related_searches": [
                  "Best coffee shops",
                  "Coffee shops Pittsburgh",
                  "Coffee shops Strip District",
                  "Coffee shops Philadelphia",
                  "Coffee shops downtown Pittsburgh",
                  "Best coffee shops Pittsburgh",
                  "Best coffee shops in Philadelphia for working",
                  "Coffee Shops Sewickley"
                ],
                "related_searches_urls": [
                  "https://www.google.com/search?sca_esv=525e608177515078&hl=en&gl=us&q=Best+coffee+shops&sa=X&ved=2ahUKEwiq0P6Xv8yUAxUPNvsDHaaIEQsQ1QJ6BAg1EAE",
                  "https://www.google.com/search?sca_esv=525e608177515078&hl=en&gl=us&q=Coffee+shops+Pittsburgh&sa=X&ved=2ahUKEwiq0P6Xv8yUAxUPNvsDHaaIEQsQ1QJ6BAg8EAE",
                  "https://www.google.com/search?sca_esv=525e608177515078&hl=en&gl=us&q=Coffee+shops+Strip+District&sa=X&ved=2ahUKEwiq0P6Xv8yUAxUPNvsDHaaIEQsQ1QJ6BAg_EAE",
                  "https://www.google.com/search?sca_esv=525e608177515078&hl=en&gl=us&q=Coffee+shops+Philadelphia&sa=X&ved=2ahUKEwiq0P6Xv8yUAxUPNvsDHaaIEQsQ1QJ6BAhBEAE",
                  "https://www.google.com/search?sca_esv=525e608177515078&hl=en&gl=us&q=Coffee+shops+downtown+Pittsburgh&sa=X&ved=2ahUKEwiq0P6Xv8yUAxUPNvsDHaaIEQsQ1QJ6BAg-EAE",
                  "https://www.google.com/search?sca_esv=525e608177515078&hl=en&gl=us&q=Best+coffee+shops+Pittsburgh&sa=X&ved=2ahUKEwiq0P6Xv8yUAxUPNvsDHaaIEQsQ1QJ6BAg6EAE",
                  "https://www.google.com/search?sca_esv=525e608177515078&hl=en&gl=us&q=Best+coffee+shops+in+Philadelphia+for+working&sa=X&ved=2ahUKEwiq0P6Xv8yUAxUPNvsDHaaIEQsQ1QJ6BAg7EAE",
                  "https://www.google.com/search?sca_esv=525e608177515078&hl=en&gl=us&q=Coffee+Shops+Sewickley&sa=X&ved=2ahUKEwiq0P6Xv8yUAxUPNvsDHaaIEQsQ1QJ6BAg5EAE"
                ]
              }
            ],
            "search_information": {
              "no_results_for_original_query_found": false,
              "query": "coffee shops",
              "showing_results_for": "coffee shops",
              "time_taken_displayed": null,
              "total_results_count": 403000000
            },
            "total_results_count": 403000000,
            "what_people_are_saying": {
              "items": [
                {
                  "engagement_timeframe": "2 reactions, 3 days ago",
                  "pos": 1,
                  "source": "Facebook",
                  "title": "Will be working in Frederick every Monday for the foreseeable future (driving from Westminster)...what's your fave coffee shop in the area?",
                  "url": "https://www.facebook.com/groups/366748512662939/posts/968510169153434/"
                },
                {
                  "engagement_timeframe": "90+ comments, 18 hours ago",
                  "pos": 2,
                  "source": "Reddit",
                  "title": "Portland coffee roaster scoops up another empty Starbucks cafe",
                  "url": "https://www.reddit.com/r/Portland/comments/1tjmv4s/portland_coffee_roaster_scoops_up_another_empty/"
                },
                {
                  "engagement_timeframe": "1.5M+ views, 1 week ago",
                  "pos": 3,
                  "source": "Los Angeles",
                  "title": "Auntie Nid Coffee Shop 🇹🇭 aka ร้านป้านิดปากแดง กาแฟโบราณ (Pa Nid Pak Daeng Kafaeboran) #auntienidcoffeeshop #auntienid",
                  "url": "https://www.tiktok.com/@janiedevours/video/7640013933008440606"
                }
              ],
              "pos_overall": 5
            }
          },
          "url": "https://www.google.com/search?q=coffee+shops&hl=en&gl=us"
        },
        "errors": [],
        "status_code": 12000,
        "task_id": "7463508496927950850"
      },
      "headers": {},
      "status_code": 200,
      "url": "https://www.google.com/search?q=coffee+shops&hl=en&gl=us",
      "query": "coffee shops",
      "task_id": "7463508496927950850",
      "created_at": "2026-05-22 08:38:10",
      "updated_at": "2026-05-22 08:38:13"
    }
  ]
}

配置

const client = new DecodoClient({
  webScrapingApi: {
    apiKey: '<api_key>',
  },
  timeoutMs: 120_000, // optional, request timeout in ms (default: 180s)
});

也通过 apiKey 或者说 token而不是两个。 如果两者兼备,客户都会抛出.

// Basic authentication token (older plans)
const client = new DecodoClient({
  webScrapingApi: {
    token: '<basic_auth_token>',
  },
});
参数说明
apiKeyWeb Data API 键. 建议
tokenWeb scrating API 基本认证符,用于更古老的计划. 用它来代替 apiKey
timeoutMs请求超时以毫秒计( 默认: 180000)

网络搜索 API

通过 client.webScrapingApi。 。 。 .

下面的片段假设您已经导入 Target (和 DecodoClient 例如:

import { DecodoClient, Target } from '@decodo/sdk-ts';

同步刮擦

等待刮出结果后返回:

const result = await client.webScrapingApi.scrape({
  target: Target.AmazonProduct,
  query: 'B09H74FXNW',
  parse: true,
});

Async 刮伤

创建刮取任务并立即返回。 任务状态和结果单选:

const task = await client.webScrapingApi.scrapeAsync({
  target: Target.GoogleSearch,
  query: 'laptop reviews',
  parse: true,
});

const meta = await client.webScrapingApi.getStatus(task.id);
console.log(meta.status); // 'pending' | 'done' | 'faulted'

const results = await client.webScrapingApi.getResults(task.id);

批发

在单个请求中发送多个查询或 URL :

const batch = await client.webScrapingApi.scrapeBatch({
  target: Target.GoogleSearch,
  query: ['coffee', 'tea', 'juice'],
  parse: true,
});

const coffeeTaskId = batch.queries[0].id;

await client.webScrapingApi.getResults(coffeeTaskId);

运行网页搜索并返回结果页。 要求数 apiKey数字 :

const serp = await client.webScrapingApi.search({
  query: 'laptop reviews',
  geo: 'United States',
});

地图

在网站上发现了链接。 要求数 apiKey数字 :

const map = await client.webScrapingApi.map({
  url: 'https://example.com',
  limit: 100,
});

const links = map.results[0].content.links;

爬行

开始一个爬行, 投票它的地位 并返回每页 一旦它解决。 要求数 apiKey数字 :

const { status, pages } = await client.webScrapingApi.crawl(
  { url: 'https://example.com', limit: 50, output: 'markdown' },
  { pollInterval: 5_000, timeout: 600_000 },
);

if (status.status !== 'done') {
  console.warn(`Crawl ended ${status.status}; ${pages.length} pages collected`);
}

crawl 爬行结束时不会扔出 faulted, (中文(简体) ), cancelled 或者说 truncated它返回迄今为止收集的页面,以及 status 是完整的爬行状态对象,所以检查 status.status 在依赖之前 pages如果爬行还没有解决 timeout, (中文(简体) ), crawl 丢出一个 TimeoutError 而爬行会不停地运行在服务器上;呼叫 cancelCrawl 来阻止它.

为了逐个推进

const job = await client.webScrapingApi.startCrawl({ url: 'https://example.com' });

const progress = await client.webScrapingApi.getCrawlStatus(job.crawl_id);
console.log(progress.status); // 'pending' | 'done' | 'faulted' | 'cancelled' | 'truncated'

const pages = await client.webScrapingApi.getCrawlResults(job.crawl_id);

const firstPage = await client.webScrapingApi.listCrawlPages(job.crawl_id);

if (firstPage.next) {
  await client.webScrapingApi.listCrawlPages(job.crawl_id, { cursor: firstPage.next });
}

await client.webScrapingApi.cancelCrawl(job.crawl_id);

支助目标

每个目标接受一个主要输入参数(url, (中文(简体) ), query, (中文(简体) ), product_id,或 prompt)和可选配置。 以下实例显示可调用的最低有效载荷 client.webScrapingApi.scrape(...)。 。 。 .

搜索引擎

目标说明示例
Target.GoogleSearch查询的 Google 搜索结果{ target: Target.GoogleSearch, query: "coffee shops" }
Target.GoogleLensGoogle 镜头反向图像搜索{ target: Target.GoogleLens, query: "https://example.com/cat.jpg" }
Target.BingSearchBing 搜索结果{ target: Target.BingSearch, query: "electric vehicles" }

电子商务

目标说明示例
Target.AmazonProduct亚马逊产品详情页面 由ASIN{ target: Target.AmazonProduct, query: "B09H74FXNW" }
Target.AmazonSearch亚马逊搜索结果{ target: Target.AmazonSearch, query: "laptop" }
Target.AmazonPricing亚马逊定价和报价{ target: Target.AmazonPricing, query: "B09H74FXNW" }
Target.WalmartProduct按产品标识分列的沃尔玛产品页{ target: Target.WalmartProduct, product_id: "15296401808" }
Target.TargetProductObject.com 产品页按产品标识{ target: Target.TargetProduct, product_id: "92186007" }

社交媒体

目标说明示例
Target.RedditPost通过 URL 编辑文章{ target: Target.RedditPost, url: "https://reddit.com/r/nba/..." }
Target.RedditSubreddit由 URL 子编辑 Reddit{ target: Target.RedditSubreddit, url: "https://reddit.com/r/nba/" }
Target.YoutubeMetadata根据ID制作的YouTube视频元数据{ target: Target.YoutubeMetadata, query: "dFu9aKJoqGg" }
Target.YoutubeSearchYouTube 搜索结果{ target: Target.YoutubeSearch, query: "ambient music" }
Target.TiktokPostTikTok 贴出 URL{ target: Target.TiktokPost, url: "https://www.tiktok.com/@nba/video/..." }

AI 工具

目标说明示例
Target.Chatgpt快速的 ChatGPT 响应{ target: Target.Chatgpt, prompt: "What are the top three dog breeds?" }
Target.Perplexity快速的困惑反应{ target: Target.Perplexity, prompt: "What causes seasonal allergies?" }
Target.Gemini双子座反应迅速{ target: Target.Gemini, prompt: "What are the top three dog breeds?" }
Target.GoogleAiModeGoogle AI 模式响应{ target: Target.GoogleAiMode, query: "What are the top three dog breeds?" }

普遍刮去

目标说明示例
Target.Universal通过通用刮取器的任何 URL{ target: Target.Universal, url: "https://example.com" }
Target.Google原始 Google URL 刮取{ target: Target.Google, url: "https://google.com/search?q=laptop" }
Target.AmazonRaw 亚马逊 URL 刮取{ target: Target.Amazon, url: "https://amazon.com/dp/B09H74FXNW" }

完整的目标列表和参数详情见API文档:

处理错误

SDK 将映射到 API 错误代码的打出错误 :

import {
  DecodoError,
  AuthenticationError,
  RateLimitError,
  ValidationError,
  TimeoutError,
  Target,
} from '@decodo/sdk-ts';

try {
  await client.webScrapingApi.scrape({
    target: Target.GoogleSearch,
    query: 'test',
    parse: true,
  });
} catch (err) {
  if (err instanceof AuthenticationError) {
    // 401/403 — bad credentials
  } else if (err instanceof RateLimitError) {
    // 429 — too many requests
  } else if (err instanceof ValidationError) {
    // 422 — invalid parameters
    console.log(err.errors);
  } else if (err instanceof TimeoutError) {
    // request timed out
  }
}

开始吧

使用 Decodo 网页搜索 API 构建刮取工作流程 :

许可证

释放 MIT 许可证。 。 。 .

版本与发布记录

@decodo/sdk-ts 共发布 15 个版本,首次发布于 2025/08/25;过去 12 个月发布了 12 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
3.0.0latest2026/10/3012 天前
2.7.02026/10/1329 天前
2.6.12026/10/1230 天前
2.5.02026/10/091 个月前
2.4.02026/10/061 个月前
2.3.02026/09/082 个月前

关于 @decodo/sdk-ts 的常见问题

@decodo/sdk-ts 是什么?

Decodo API 的官方类型SDK脚本

如何安装 @decodo/sdk-ts?

在项目目录运行 npm install @decodo/sdk-ts,或使用 pnpm add / yarn add / bun add。

@decodo/sdk-ts 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@decodo/sdk-ts 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@decodo/sdk-ts 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@decodo/sdk-ts 可以商用吗?

@decodo/sdk-ts 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@decodo/sdk-ts 的下载量有多少?

根据 npm 官方下载统计,@decodo/sdk-ts 在 2026/10/12 – 2026/11/10 这 30 天内被下载 9,008 次,日均约 300 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@decodo/sdk-ts 还在维护吗?

最新版本 3.0.0 发布于 2026/10/30(12 天前);至今共发布 15 个版本,其中过去 12 个月发布了 12 个;首次发布于 2025/08/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。