问题描述
lastMonthEnd.strftime("%d"),lastMonthEnd.strftime("%b") and lastMonthEnd.strftime("%Y")
在一个变量中两次。
我声明了时间变量。
today = date.today()
first = today.replace(day=1)
lastMonthEnd = first + dateutil.relativedelta.relativedelta(days=-1)
lastQuaterBegin = first + dateutil.relativedelta.relativedelta(months=-3)
lastMonthBegin = first + dateutil.relativedelta.relativedelta(months=-1)
我得到的第一个URL没有任何问题
# Get P&L monthly
plUrl = "https://go.xero.com/Reports/Report2.aspx?"\
"reportId=ca205001-1651-4947-bf95-9b1436926f09&report=&statement"\
"=a22c12ce-7b22-49ff-a674-1a509552f6de&attPage=Compare%20Periods&"\
"date="+lastMonthEnd.strftime("%d")+"%20"+lastMonthEnd.strftime("%b")+"%20"+lastMonthEnd.strftime("%Y")+\
"&timeframe=1&periods=3&budgetID=%20&total=null&ytd=null&"\
"&CompareDaterangePeriods=1&sortByForAccount=Formattedname&cashOnly=null"
driver.get(plUrl)
但是,当我在下面的代码中两次在网址中有lastMonthEnd.strftime("%d"),lastMonthEnd.strftime("%b") and lastMonthEnd.strftime("%Y")
的位置运行代码时,会得到一个
文件“ XXX”,第145行,在模块中 “ toDate =” + lastMonthEnd.strftime(“%d”)+“%20” + lastMonthEnd.strftime(“%b”)+“%20” + lastMonthEnd.strftime(“%Y”)+“&” \
TypeError:“ datetime.date”对象不可调用
错误。
plUrl = "https://go.xero.com/Reports/Report2.aspx?reportId=ca205001-1651-4947-bf95-9b1436926f09&report=&"\
"statement=a22c12ce-7b22-49ff-a674-1a509552f6de&attPage=Show%20Date%20Range&"\
"date="+lastMonthEnd.strftime("%d")+"%20"+lastMonthEnd.strftime("%b")+"%20"+lastMonthEnd.strftime("%Y")+"&"\
"timeframe=1&periods=3&budgetID=%20&total=null&ytd=null&"\
"fromDate="+lastQuaterBegin("%d")+"%20"+lastQuaterBegin("%b")+"%20"+lastQuaterBegin("%Y")+"&"\
"toDate="+lastMonthEnd.strftime("%d")+"%20"+lastMonthEnd.strftime("%b")+"%20"+lastMonthEnd.strftime("%Y")+"&"\
"CompareDaterangePeriod=none&CompareDaterangePeriods=1&sortByForAccount=Formattedname&cashOnly=null"
driver.get(plUrl)
有人可以帮助解决这个问题吗?
解决方法
似乎您忘记了在某些.strftime
对象上添加DateTime
。
编码愉快, 面包果