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:预期的字符串或类似字节的对象
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:预期的字符串或类似字节的对象
您必须尝试提取标识为日期时间字符串的字符串。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']