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("&nbsp&nbsp&nbsp&nbsp&nbsp");
document.write("农历日期:"+x[i].getElementsByTagName("nl")[0].childNodes[0].nodeValue);
document.write("&nbsp&nbsp&nbsp&nbsp&nbsp");

// document.write("</div>");
// document.write("<div class='aaaa'>");
document.write("干支日期:"+x[i].getElementsByTagName("gz")[0].childNodes[0].nodeValue);
document.write("&nbsp&nbsp&nbsp&nbsp&nbsp");
//document.write("</div>");
// document.write("<div class='aaaa'>");
document.write(x[i].getElementsByTagName("y")[0].childNodes[0].nodeValue);
document.write("&nbsp&nbsp&nbsp&nbsp&nbsp");
// document.write("</div>");
// document.write("<div class='aaaa'>");
document.write(x[i].getElementsByTagName("j")[0].childNodes[0].nodeValue);
document.write("&nbsp&nbsp&nbsp&nbsp&nbsp");
document.write("</div>");
}
</script>

<div id ='cind'>

</div>
2、XML
<yearstr>
<today>2023-05-08</today>
<nl>&#20108;&#38646;&#20108;&#19977;&#24180; &#19977;&#26376;(&#23567;) &#21313;&#20061;</nl>&gt;
<gz>&#30328;&#21359;&#24180; &#19969;&#24051;&#26376; &#19993;&#23493;&#26085;</gz>
<y>&#23452;&#65306;&#32467;&#23130; &#23233;&#23094;&#12289;&#32435;&#37319;&#12289;&#26053;&#34892; &#20986;&#28216; &#20986;&#34892;&#12289;&#25644;&#23478; &#31227;&#24473;&#12289;&#25644;&#36801;&#26032;&#23429; &#20052;&#36801;&#26032;&#23621; &#20837;&#23429;&#12289;</y>
<j>&#24524;:&#21160;&#22303; &#30772;&#22303; &#23433;&#33900;</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

BAT

@echo on
cd C:\Users\lion\PycharmProjects\WSD\
python chf.py

CHOICE /T 3 /C yc /D y /n // 等到3秒











posted on 2023-05-08 23:01  Lionever  阅读(17)  评论(0编辑  收藏  举报