尝试用python减去两个日期并得到以小时(大于24小时的时间段)为单位的结果
这就是我所尝试的:
currentdate = datetime.now()
# gets the date from the website
lastcrawl = driver.find_element_by_xpath('//*[@id="last-15336"]/h4').text
# convert string into time format
formatlastcrawl = datetime.strptime(lastcrawl, '%b %d %H:%M')
# converts into the time format - April 28, 11:24
newformatlastcrawl = formatlastcrawl.strftime('%b %d %H:%M')
print newformatlastcrawl
# substracts 24 hours of the current date(because the website crawl happens every 24 hours) + 2 hours(to give enough time to finish the crawl)
substractdate = (currentdate - timedelta(hours=26)).strftime("%b %d %H:%M")
print substractdate
# changes the format of the current date. For example - Nov 12
formatcurrentdate = currentdate.strftime("%b %d %H:%M")
print formatcurrentdate
a = (substractdate - newformatlastcrawl)
print a
当我试图减去它时,我得到一个错误:
a=(substractdate-newformatlastcrawl).strTime(“%b%d%H:%M”) TypeError:不支持-:“str”和“str”的操作数类型
我只想在几个小时内得到答案。此外,时间值可以大于24小时
这个程序在小时内打印两次之间的差异。在
相关问题 更多 >
编程相关推荐