手动设置日期格式容易出错-您更改了变量的名称-
month
从未用于创建URI和
mesec
d.month > 9
. 请参阅@metatoaster的评论。
strftime - date formatting
:
import datetime
d = datetime.date(2012,1,1)
# avoid off-by-1 leap-year mishaps due to hardcoded days/year
while d.year < 2013:
# format as dd.mm.yyyy including leading 0 if need be
dd = d.strftime("%d.%m.%Y")
print("http://www.ljse.si/cgi-bin/jve.cgi?doc=2561&subtab=0_2&date1="+dd)
d = d + datetime.timedelta(days=1)
输出(用于
d = d + datetime.timedelta(days=36)
http://www.ljse.si/cgi-bin/jve.cgi?doc=2561&subtab=0_2&date1=01.01.2012
http://www.ljse.si/cgi-bin/jve.cgi?doc=2561&subtab=0_2&date1=06.02.2012
http://www.ljse.si/cgi-bin/jve.cgi?doc=2561&subtab=0_2&date1=13.03.2012
http://www.ljse.si/cgi-bin/jve.cgi?doc=2561&subtab=0_2&date1=18.04.2012
http://www.ljse.si/cgi-bin/jve.cgi?doc=2561&subtab=0_2&date1=24.05.2012
http://www.ljse.si/cgi-bin/jve.cgi?doc=2561&subtab=0_2&date1=29.06.2012
http://www.ljse.si/cgi-bin/jve.cgi?doc=2561&subtab=0_2&date1=04.08.2012
http://www.ljse.si/cgi-bin/jve.cgi?doc=2561&subtab=0_2&date1=09.09.2012
http://www.ljse.si/cgi-bin/jve.cgi?doc=2561&subtab=0_2&date1=15.10.2012
http://www.ljse.si/cgi-bin/jve.cgi?doc=2561&subtab=0_2&date1=20.11.2012
http://www.ljse.si/cgi-bin/jve.cgi?doc=2561&subtab=0_2&date1=26.12.2012