Status: ✓ Running
使用 Playwright 进行网页抓取的 HTTP API 服务,支持 JS 渲染和反爬虫特性。
当前页面 - API 使用文档
抓取网页内容(支持 JS 渲染)
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
url |
string | ✓ | - | 要抓取的网页 URL |
wait_until |
string | 可选 | networkidle |
等待策略:load, domcontentloaded, networkidle |
timeout |
integer | 可选 | 30000 |
超时时间(毫秒),范围:1000 - 120000 |
| 字段 | 类型 | 说明 |
|---|---|---|
content |
string | 渲染后的完整 HTML 内容 |
url |
string | 最终 URL(处理重定向后) |
title |
string | 页面标题 |
如何使用:在请求中添加 -H "X-API-Key: your-api-key-here"
请联系服务管理员获取 API key。
curl -X POST https://playwright.yibozhang.me/fetch \
-H "X-API-Key: your-api-key-here" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com",
"wait_until": "networkidle",
"timeout": 30000
}'
import requests
response = requests.post(
"https://playwright.yibozhang.me/fetch",
headers={
"X-API-Key": "your-api-key-here",
"Content-Type": "application/json"
},
json={
"url": "https://example.com",
"wait_until": "networkidle",
"timeout": 30000
}
)
result = response.json()
print(f"Title: {result['title']}")
print(f"Content length: {len(result['content'])}")
注意:本地访问可以省略 X-API-Key 请求头。
load - 页面完全加载(包括所有资源)domcontentloaded - DOM 内容加载完成(较快,但可能缺少动态内容)networkidle - 网络空闲(推荐,适合 SPA 和动态页面)Playwright HTTP Service | Powered by FastAPI + Playwright