matches = list(datefinder.find_dates(str(laslogsystime[0])))
if len(matches) > 0:
date = matches[0]
# print(date)
logging = re.findall(r'(.*?)', date)[0]
print(logging)
TypeError:预期的字符串或类似字节的对象
答案 0 :(得分:0)
您必须尝试提取datefinder
标识为日期时间字符串的字符串。
您不需要re.findall
,您需要通过传递find_dates
参数告诉source=True
返回包含日期时间和源字符串的元组:
import datefinder
from datetime import datetime
laslogsystime = "August 1990 some text May 21 2015"
matches = [src for time, src in datefinder.find_dates(laslogsystime, source=True)]
print(matches) # => ['August 1990', 'May 21 2015']