赞
踩
如图,准备开发一套老黄历网站,需要体现出农历、老黄历、万年历,同时返回干支、福神、宜忌、节假日、吉凶、冲煞、分时吉凶等信息,下面直接上代码,用Python
# -*- coding: UTF-8 -*- ''' Python 3.x 数据无忧 Created on 2021年07月11日 描述:老黄历查询 示例代码 @author: api.data5u.com ''' import requests; import time; import threading; import urllib3; if __name__ == '__main__': domain = "http://api.data5u.com"; apiUrl = "/calendar/lunar"; ''' 参数值请自行补全 ''' params = {"appsec":"","date":""}; method = "POST"; res = requests.post(domain + apiUrl, params ).content.decode() print( res )
下面看下如果用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 = "/calendar/lunar"; String params = "appsec=&date="; // 参数值请自行补全 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()); } }
上面代码输出的信息如下,JSON格式
{ "code":"AJAX_SUCCESS", "msg":"操作成功", "data":{ "liu_yao":"佛灭", "wu_hou":"戴胜降于桑", "nian_gan_zhi":"辛丑年 属牛 壁上土", "yue_gan_zhi":"壬辰月 属龙 长流水", "ri_gan_zhi":"己酉日 属鸡 大驿土", "gong_li":"2021年5月1日", "weekday":"六", "xing_zuo":"金牛", "run_nian":false, "fading_jie_ri":"劳动节,", "qita_jie_ri":"", "nong_li":"二〇二一年三月二十日", "jie_qi":"", "li_chun":"2021-02-03 22:58:39", "si_shen_shou":"朱雀", "yue_tai_shen":"占门堂", "tai_shen":"占大门外东北", "xi_shen":"东北", "cai_shen":"正北", "fu_shen":"正南", "pengzu_ji_hui":"己不破券二比并亡 酉不会客醉坐颠狂", "chong":"鸡日 冲(癸卯)兔", "sha":"东", "xing_xiu":"南方柳土獐(凶)", "xing_xiu_ge":"柳星造作主遭官,昼夜偷闭不暂安,埋葬瘟惶多疾病,田园退尽守冬寒,开门放水遭聋瞎,腰驼背曲似弓弯,更有棒刑宜谨慎,妇人随客走盘桓。", "zhi_xing":"执", "tian_shen":"天德黄道(吉)", "shi_yi":"祭祀,祈福,求嗣,开光,解除,出火,拆卸,入宅,安床,修造,安门,纳畜,启钻,安葬,", "jin_ji":"动土,破土,纳财,掘井,挂匾,开市,伐木,交易,", "jiu_xing":"四绿木 巽(东南) 天权 玄空[文曲 吉] 奇门[天辅 大吉 杜门 阳] 太乙[招摇 安神]", "yue_xiang":"更待", "shu_jiu":null, "san_fu":null, "kong_wang":"年=辰巳 月=午未 日=寅卯", "qian_jie_qi":"谷雨 2021-04-20 04:33:14", "hou_jie_qi":"立夏 2021-05-05 14:47:01", "time_list":[ { "time":"0:00-0:59", "gan_zhi":"甲子", "chong":"(戊午)马", "sha":"南", "na_yin":"海中金", "tian_shen":"司命", "hei_huang_dao":"黄道", "ji_xiong":"吉", "shi_yi":"无,", "jin_ji":"赴任,词讼,修造,动土," }, { "time":"1:00-2:59", "gan_zhi":"乙丑", "chong":"(己未)羊", "sha":"东", "na_yin":"海中金", "tian_shen":"勾陈", "hei_huang_dao":"黑道", "ji_xiong":"凶", "shi_yi":"无,", "jin_ji":"诸事不宜," }, ...... { "time":"23:00-23:59", "gan_zhi":"丙子", "chong":"(庚午)马", "sha":"南", "na_yin":"涧下水", "tian_shen":"天牢", "hei_huang_dao":"黑道", "ji_xiong":"凶", "shi_yi":"订婚,嫁娶,安床,移徙,入宅,修造,安葬,见贵,求财,", "jin_ji":"祭祀,祈福,斋醮,开光,赴任,出行," } ] }, "timeMs":336, "success":true }
好了,有了这些数据就够了,包含了每日宜忌、天神、冲煞、星宿、干支等等。
数据接口是免费的,这个地址 https://api.data5u.com/apiinfo/20003.html
就这么多吧。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。