开发一个包含唐诗三百首、宋词、元曲类APP
免费的接口地址:https://api.data5u.com/apiinfo/80004.html
提供诗词大全,包含唐诗、宋词、元曲、近现代诗词等涉及内容和诗词点评,还可以查询诗人的详细信息。
获取诗人信息
{
"code":"AJAX_SUCCESS",
"msg":"操作成功",
"data":{
"name":"李白",
"dynasty":"唐代",
"basic":"李白 (701-762)当然是大家公认的我国古代最伟大的天才诗人之一,大多数人认为他同时也是一位伟大的词人。他祖籍陇西(今甘肃),一说生于中亚,但少年时即生活在蜀地,壮年漫游天下,学道学剑,好酒任侠,笑傲王侯,一度入供奉,但不久便离开了,后竟被流放到夜郎(今贵州)。 他的诗,想象力“欲上青天揽明月”,气势如“黄河之水天上来”,的确无人能及。北宋初年,人们发现《菩萨蛮》“平林漠漠烟如织”和《忆秦娥》“秦娥梦断秦楼月”两词,又尊他为词的始祖。有人怀疑那是后人所托,至今聚讼纷纭。其实, 李白 的乐府诗,当时已被之管弦,就是词的滥觞了。至于历来被称为“百代词曲之祖”的这两首词,格调高绝,气象阔大,如果不属于 李白 ,又算作谁的作品为好呢?"
},
"timeMs":53,
"success":true
}
获取诗人名下的诗词
{
"code":"AJAX_SUCCESS",
"msg":"操作成功",
"data":{
"currPage":2,
"dataList":[
{
"idx":"6a5dc16a0b97945d1d352fdf8e484053",
"url":null,
"title":"春怨",
"author":"李白",
"dynasty":"唐诗",
"type":"乐府",
"content":"白马金羁辽海东,罗帷绣被卧春风。 落月低轩窥烛尽,飞花入户笑床空。",
"comment":"",
"from":"唐诗:卷184_31"
},
{
"idx":"3c01333c02d636a8643db89773265a52",
"url":null,
"title":"别东林寺僧",
"author":"李白",
"dynasty":"唐诗",
"type":"五绝",
"content":"东林送客处,月出白猿啼。 笑别庐山远,何烦过虎溪。",
"comment":"",
"from":"唐诗:卷174_20"
}
],
"pageSize":2,
"totalCount":788,
"maxPage":394
},
"timeMs":64,
"success":true
}
获取诗词详情
{
"code":"AJAX_SUCCESS",
"msg":"操作成功",
"data":{
"idx":"f40c4b6a07868dd9a96420c585a8a9d6",
"url":null,
"title":"寒食都门作",
"author":"胡曾",
"dynasty":"唐诗",
"type":"七律",
"content":"二年寒食住京华,寓目春风万万家。 金络马衔原上草,玉颜人折路傍花。 轩车竞出红尘合,冠盖争回白日斜。 谁念都门两行泪,故园寥落在长沙。",
"comment":"",
"from":"唐诗:卷647-2"
},
"timeMs":1912,
"success":true
}
============================================================
有了数据,下一步就看代码了,根据诗名字获取古诗详细 Java 参考代码
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
/**
* 根据诗名字获取古诗详细 示例代码
**/
public class PostTest {
public static void main(String[] args) throws Exception {
String domain = "http://api.data5u.com";
String api = "/shici/get-poem-by-name";
String params = "appsec=&name="; // 参数值请自行补全
String method = "POST";
HttpURLConnection connection = null;
URL link = new URL(domain + api);
connection = (HttpURLConnection)link.openConnection();
connection.setRequestMethod(method);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setReadTimeout(10000);
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(connection.getOutputStream(),"UTF-8"));
out.write(params);
out.flush();
out.close();
String line = null;
StringBuilder html = new StringBuilder();
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
while((line = reader.readLine()) != null){
html.append(line);
}
try {
if (reader != null) {
reader.close();
}
} catch (Exception e) {
}
System.out.println(html.toString());
}
}