1

I'm scraping data from a website and I would like to know when this data are updated. But on the site there is not an absolute data, only a reference like this: Updated on Monday 21:00 or this one, Update 1 day ago. Anyone can help me to get the timestamp from these strings? Thanks

4
  • What input u have and what output u expect? Commented Dec 1, 2015 at 10:46
  • @Lafada I have in input strings like: Updated on Monday 21:00 or Updated 1 day ago and I would like to transform these strings in 23/11/2015 21:00 Commented Dec 1, 2015 at 10:51
  • 3
    consider checking - github.com/bear/parsedatetime Commented Dec 1, 2015 at 10:56
  • @TomRon This library is perfect for my job. Thanks a lot TomRon! Commented Dec 1, 2015 at 11:20

1 Answer 1

1

You could use parsedatetime module as @Tom Ron suggested:

#!/usr/bin/env python import parsedatetime as ptd ptc = ptd.Constants() ptc.YearParseStyle = 0 # avoid future year ptc.DOWParseStyle = 0 # how weekday is parsed cal = ptd.Calendar(ptc) for human_time in ["Updated on Monday 21:00", "1 day ago"]: print(cal.parseDT(human_time)[0]) 

Output

2015-11-30 21:00:00 2015-11-30 20:49:03 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.