I have a web crawler and I'm trying to remove the clock time from the DateTime. for example from the crawler I got "29 January 2019 09:46:46", how to remove or replace the "9:46:46" so that only "29 January 2019" left.
I have tried to write this code but it results in nothing. I use ".replace(time, ' ')" to remove the hours, minute, and second. But it looks like remove all the DateTime.
date_time = record.find('i').replace(time, ' ')
from the date_time I got dates based on the date on the website that I crawled. But I hope to get only the date, months, and year without the hours, minutes and seconds.
Perhaps try this:
import re
text = "29 january 2019 09:46:46"
justDate = re.split('\s\d{0,2}:\d{0,2}:\d{0,2}', text)[0]
Output:
justDate
Out[60]: '29 january 2019'
Edit:
OP also asked how to get just the time part of the string. To do so:
justTime = re.split('\d{4}\s', text)[1]
Output:
justTime
Out[61]: '09:46:46'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.