import { DataifyClient } from "dataify-sdk";
// 用 apiKey 初始化客户端(也可改用环境变量 DATAIFY_API_KEY)
const client = new DataifyClient({
apiKey: "your_api_key_here",
});DataifyClient 构造参数(DataifyClientOptions):| 参数 | 说明 | 默认值 |
|---|---|---|
apiKey | Dataify API Key | 必填 |
scraperBaseUrl | Scraper / SERP 基址 | https://scraperapi.dataify.com |
webUnlockerBaseUrl | Web Unlocker 基址 | https://webunlocker.dataify.com |
timeoutMs | 请求超时(毫秒) | 内置默认 |
fetchImpl | 自定义 fetch 实现 | 全局 fetch |
Promise,使用 await:import { DataifyClient } from "dataify-sdk";
// 从环境变量读取 key(生产推荐)
const client = new DataifyClient({
apiKey: process.env.DATAIFY_API_KEY!,
});
async function main() {
// 所有调用返回 Promise,需用 await 取结果
const result = await client.tools.google({ q: "Dataify", json: "1" });
console.log(result);
}
// 顶层 await 不可用,用 .catch 兜住异常
main().catch(console.error);client.tools 下,按引擎命名(如 google、bing、googleImages、googleNews)。以下按引擎分列(若把文档部署到 VitePress / Docusaurus,可将下列分节改写为 <Tabs> 交互标签):// q 为关键词;json:"1" 让上游返回 JSON 而非 HTML
const result = await client.tools.google({
q: "best shoes of 2025",
json: "1",
});
console.log(result);const result = await client.tools.googleImages({
q: "noise cancelling headphones",
});
console.log(result);const news = await client.tools.googleNews({ q: "AI latest" });
const trends = await client.tools.googleTrends({ q: "fashion" });
const maps = await client.tools.googleMaps({ q: "coffee shop near me" });const result = await client.tools.bing({ q: "python tutorial" });
console.log(result);全部 SERP 方法见 client.tools.specs。
client.tools 下,方法名采用小驼峰(如 amazonProductByAsin、linkedinCompanyInformationByUrl)。以下按平台分列:// 按 ASIN 采集商品
const product = await client.tools.amazonProductByAsin({
asin: "B0BZYCJK89",
});
console.log(product);
// 按商品 URL 采集评论
const comments = await client.tools.amazonCommentByUrl({
url: "https://www.amazon.com/dp/B0BZYCJK89",
});// 按公司 URL 采集公司信息
const company = await client.tools.linkedinCompanyInformationByUrl({
url: "https://www.linkedin.com/company/example",
});
// 按关键词采集职位列表
const jobs = await client.tools.linkedinJobListingsInformationByKeyword({
keyword: "data engineer",
location: "Remote",
});const profile = await client.tools.insProfilesByUsername({ username: "nasa" });
const video = await client.tools.youtubeProductById({ videoId: "dQw4w9WgXcQ" });
const item = await client.tools.walmartProductByUrl({ url: "https://www.walmart.com/ip/..." });全部工具名(含参数)见 client.tools.specs,或在 IDE 中将鼠标悬停在client.tools上查看完整列表与类型提示。
// 解锁并抓取任意网页
const result = await client.webUnlocker.request({
url: "https://example.com",
type: "html",
js_render: false, // 是否渲染 JS
});
console.log(result);// 按 task id 下载 JSON 结果
const json = await client.scraper.downloadTaskResult("task_id_here");
console.log(json);
// 下载为文件(格式:xlsx / csv / json)
const response = await client.scraper.downloadTaskFile("task_id_here", "xlsx");
console.log(response.status);| 能力 | 端点 |
|---|---|
| Scraper / SERP | https://scraperapi.dataify.com |
| Web Unlocker | https://webunlocker.dataify.com |
Authorization: Bearer <apiKey>。dataify-sdk → Dataify APIs。ParamRecord、返回值均有完整类型标注;在 VS Code / WebStorm 中将鼠标悬停在 client.tools.amazonProductByAsin 等上即可看到参数与文档。client.tools.specs 自省全部工具元信息(含 params / required / id)。Promise,用 try/catch 捕获异常;异常对象(网络/上游错误)含 status 与 body 字段:try {
const r = await client.tools.google({ q: "Dataify", json: "1" });
console.log(r);
} catch (e: any) {
// 异常对象含 status(HTTP 状态码)与 body(响应体)
console.error("HTTP", e?.status, "body:", e?.body ?? e?.message);
}import { DataifyClient } from "dataify-sdk";
// 1) 用环境变量 key 初始化客户端
const client = new DataifyClient({
apiKey: process.env.DATAIFY_API_KEY!,
});
async function main() {
// 2) SERP:Google 搜索
const result = await client.tools.google({
q: "Dataify",
json: "1",
});
console.log(result);
// 3) 平台采集:按 ASIN 抓 Amazon 商品
const product = await client.tools.amazonProductByAsin({
asin: "B0BZYCJK89",
});
console.log(product);
}
main().catch(console.error);| 资源 | 说明 | 链接 |
|---|---|---|
| 📘 GitHub 仓库 | 查看源码、示例并做出贡献 | GitHub |
| 📦 npm 页面 | 软件包列表与发布历史记录 | dataify-sdk |