1、html
<script>
var date = new Date();
xmltext = new XMLHttpRequest;
xmltext.open("GET","2.xml",false);
xmltext.send();
a = xmltext.responseXML;
//document.getElementById("xmlid").innerHTML = a.getElementsByTagName("to")[2].childNodes[0].nodeValue;
x = a.getElementsByTagName("yearstr");
for(i=0;i<x.length;i++)
{
document.write("<div class='cind'>");
document.write((x[i].getElementsByTagName("today")[0].childNodes[0].nodeValue));
document.write("     ");
document.write("农历日期:"+x[i].getElementsByTagName("nl")[0].childNodes[0].nodeValue);
document.write("     ");
// document.write("</div>");
// document.write("<div class='aaaa'>");
document.write("干支日期:"+x[i].getElementsByTagName("gz")[0].childNodes[0].nodeValue);
document.write("     ");
//document.write("</div>");
// document.write("<div class='aaaa'>");
document.write(x[i].getElementsByTagName("y")[0].childNodes[0].nodeValue);
document.write("     ");
// document.write("</div>");
// document.write("<div class='aaaa'>");
document.write(x[i].getElementsByTagName("j")[0].childNodes[0].nodeValue);
document.write("     ");
document.write("</div>");
}
</script>
<div id ='cind'>
</div>
2、XML
<yearstr>
<today>2023-05-08</today>
<nl>二零二三年 三月(小) 十九</nl>>
<gz>癸卯年 丁巳月 丙寅日</gz>
<y>宜:结婚 嫁娶、纳采、旅行 出游 出行、搬家 移徙、搬迁新宅 乔迁新居 入宅、</y>
<j>忌:动土 破土 安葬</j>
</yearstr>
3、py
import requests
import xml.etree.ElementTree as ET
import datetime
tdate = datetime.date.today()
tyear = str(tdate.year)
tmon = str(tdate.month)
tday =str(tdate.day)
sday =tyear+'-'+tmon+'-'+tday
url ='*'
url2 =url+"/"+tyear+"/"+sday+'.html'
r4 = requests.get(url2)
r4.encoding ='utf-8'
r4str =r4.text
nlindex = r4str.find('农历日期')
gzrqindex = r4str.find('干支日期')
y1index = r4str.find('yj2y')
j1index = r4str.find('yj2j')
yj2y = r4str[y1index:j1index]
yendindex =yj2y.find('/p')
cindex = r4str.find('冲')
j1str =r4str[j1index+14:cindex-15]
ystr = yj2y[14:yendindex-1]
nlrq = r4str[nlindex+14:nlindex+28]
gzrq =r4str[gzrqindex+12:gzrqindex+23]
y1str ='宜:'+ystr
j2str ='忌:'+j1str
print('农历日期:'+nlrq)
print('干支日期:'+gzrq)
print(y1str)
print(j2str)
tree = ET.parse('2.xml')
root = tree.getroot()
blstr =root.find('today')
blstr.text = str(tdate)
blstr =root.find('nl')
blstr.text = nlrq
blstr =root.find('gz')
blstr.text = gzrq
blstr =root.find('y')
blstr.text = y1str
blstr =root.find('j')
blstr.text = j2str
tree.write('2.xml')
print('--------------------------------------')
# print(r4str)
# print(response.headers)
# print('-------')
# print(r1.content.decode())
# print(response.cookies.values())
# print(response.headers)
*
https://www.xingzuo5.net/calendar
标签:document,chf,write,日期,&#,nbsp,r4str,干支,find From: https://www.cnblogs.com/lionmxs/p/17383458.html