Reputation: 59
I am new in django and perhaps my problem is easy to solve but i cant find any way to resolve it in docs. I want to crape datetime from webside and store it in model as datetime field. In documentation i found something like date preprocesor but it works only for eng(and den?) language. For instance my datetime on page looks like 24 luty 20:00 and it meanse 24 February 20:00. How can scrape it? I will be gratefull for any advice
Upvotes: 0
Views: 121
Reputation: 12903
I don't know about django-dynamic-scraper, but DateTimeField
in Django supports multiple input formats:
>>> dt_field = DateTimeField(input_formats=['%Y-%m-%d %H:%M:%S', '%Y/%m/%d'])
>>> dt_field.clean("2012-11-12 11:12:23")
datetime.datetime(2012, 11, 12, 11, 12, 23, tzinfo=<django.utils.timezone.LocalTimezone object at 0x108d20090>)
>>> dt_field.clean("2015/10/9")
datetime.datetime(2015, 10, 9, 0, 0, tzinfo=<django.utils.timezone.LocalTimezone object at 0x108d20090>)
>>> dt_field.clean("123")
<traceback>
ValidationError: [u'Enter a valid date/time.']
See the docs for details.
Upvotes: 0