其他

PoetryDB

该API允许您从庞大的诗歌数据库中即时获取数据。它提供了对大量诗歌文本、作者和元数据的便捷访问,可用于文学分析、教育应用或创意项目。

查看官方文档 ↗

接入教程

1. 访问PoetryDB GitHub页面查看文档
2. 使用GET请求调用API端点(如/author, /title)
3. 解析返回的JSON数据获取诗歌信息
4. 根据需要过滤或处理诗歌内容

使用Python获取随机诗歌

python
import requests

url = 'https://poetrydb.org/random'
response = requests.get(url)
if response.status_code == 200:
    poetry_data = response.json()
    print(f"Title: {poetry_data[0]['title']}")
    print(f"Author: {poetry_data[0]['author']}")
    print("Lines:")
    for line in poetry_data[0]['lines']:
        print(line)
else:
    print(f"Error: {response.status_code}")

使用PHP搜索特定作者的诗作

php
<?php
$author = 'William Shakespeare';
$url = 'https://poetrydb.org/author/' . urlencode($author);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Accept: application/json']);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($httpCode == 200) {
    $poems = json_decode($response, true);
    if (!empty($poems)) {
        echo "Found " . count($poems) . " poems by " . $author . "\n";
        foreach ($poems as $index => $poem) {
            echo ($index + 1) . ". " . $poem['title'] . "\n";
        }
    } else {
        echo "No poems found for " . $author . "\n";
    }
} else {
    echo "Request failed with code: " . $httpCode . "\n";
}
?>

使用JavaScript获取诗歌标题列表

javascript
async function fetchPoemTitles() {
    try {
        const response = await fetch('https://poetrydb.org/title');
        if (!response.ok) {
            throw new Error(`HTTP error! status: ${response.status}`);
        }
        const data = await response.json();
        const titles = data.titles || [];
        console.log(`Total titles available: ${titles.length}`);
        // Display first 10 titles as an example
        titles.slice(0, 10).forEach((title, index) => {
            console.log(`${index + 1}. ${title}`);
        });
    } catch (error) {
        console.error('Failed to fetch poem titles:', error);
    }
}

// Call the function
fetchPoemTitles();

常见问题

PoetryDB API需要API密钥吗?

不需要。PoetryDB是一个完全免费的公共API,无需注册、API密钥或身份验证即可使用。所有数据都通过开放端点提供。

API有速率限制吗?

PoetryDB目前没有官方的速率限制,但建议合理使用以避免服务器过载。对于高频或批量请求,请考虑缓存响应或限制请求频率。

API支持哪些数据格式?

PoetryDB主要返回JSON格式的数据。所有端点都默认接受并返回JSON,使其易于集成到各种应用程序和编程语言中。

相似接口推荐

AWS SSO Identity Store

AWS SSO Identity Store是AWS IAM Identity Center(原AWS单点登录)使用的身份存储服务,提供一个统一的位置检索所有身份信息(用户和群组)。该服务简化了身份管理流程,帮助集中管理

待确认
Amazon Honeycode

Amazon Honeycode是一项全托管服务,让您无需编程即可快速为团队构建移动和Web应用。可用于管理项目、客户、运营、审批、资源乃至团队协作等各类事务。

待确认
AWS Glue

AWS Glue 是一项完全托管的提取、转换和加载(ETL)服务,可简化数据准备和集成工作。它自动发现、编目数据,并支持在数据湖和数据仓库之间进行ETL操作。

待确认
亚马逊Glacier

亚马逊S3 Glacier(简称Glacier)是一款针对“冷数据”的存储解决方案。这项超低成本的存储服务为数据备份和归档提供安全、持久且易于使用的存储方案。用户可经济高效地存储数据数月、数年甚至数十年。

待确认