[Tutor] extract date and time from string

Norman Khine norman at khine.net
Tue Aug 21 16:23:03 CEST 2012


ok, i figured it out:

>>> from BeautifulSoup import BeautifulSoup
>>> for EVENT in TABLE_CONTENT:
...     for index, item in enumerate(EVENT):
...             if index == 4:
...                     soup = BeautifulSoup(item)
...                     for a in soup.findAll('a'):
...                             print ''.join(a.findAll(text=True))
...             else:
...                     pass
...     print '=== new record ==='
...
1945/07/16 11:29:45
=== new record ===
1945/08/05 23:16:02
=== new record ===

On Tue, Aug 21, 2012 at 2:43 PM, Norman Khine <norman at khine.net> wrote:
> Hello,
> When I try this, I get the following error:
>
>
> ☹  python
>
>      * master 697cedfitools"
> Python 2.7.2 (default, Jan 28 2012, 14:53:22)
> [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import dateutil.parser as dparser
>>>> test = '<a href="javascript:c_ol(\'5393637\')" title="click date time to show origin_list (evid=5393637)">2009/05/25 00:54:45</a>'
>>>> dparser.parse(test, fuzzy=True)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "/Users/khinester/.virtualenvs/itools/lib/python2.7/site-packages/matplotlib-1.1.0-py2.7-macosx-10.5-intel.egg/dateutil/parser.py",
> line 697, in parse
>     return DEFAULTPARSER.parse(timestr, **kwargs)
>   File "/Users/khinester/.virtualenvs/itools/lib/python2.7/site-packages/matplotlib-1.1.0-py2.7-macosx-10.5-intel.egg/dateutil/parser.py",
> line 303, in parse
>     raise ValueError, "unknown string format"
> ValueError: unknown string format
>
>
> i basically have a list, like:
>
>
> TABLE_CONTENT = [['958','<a id="958F" href="javascript:c_row(\'958\')"
> title="go to map"><img src="/images/c_map.png"
> border="0"></a>','USA','Atmospheric','<a
> href="javascript:c_ol(\'958\')" title="click date time to show
> origin_list (evid=958)">1945/07/16
> 11:29:45</a>','33.6753','-106.4747','','-.03','21','','','TRINITY','&nbsp;','&nbsp;','<a
> href="javascript:c_md(\'958\')" title="click here to show source
> data">SourceData</a>','&nbsp;'],['959','<a id="959F"
> href="javascript:c_row(\'959\')" title="go to map"><img
> src="/images/c_map.png" border="0"></a>','USA','Atmospheric','<a
> href="javascript:c_ol(\'959\')" title="click date time to show
> origin_list (evid=959)">1945/08/05
> 23:16:02</a>','34.395','132.4538','','-.58','15','','','LITTLEBOY','&nbsp;','&nbsp;','<a
> href="javascript:c_md(\'959\')" title="click here to show source
> data">SourceData</a>','&nbsp;'] ..... ]
>
> from which i want to extract the date and time
>
> any advice much appreciated.
>
>
> --
> %>>> "".join( [ {'*':'@','^':'.'}.get(c,None) or
> chr(97+(ord(c)-83)%26) for c in ",adym,*)&uzq^zqf" ] )



-- 
%>>> "".join( [ {'*':'@','^':'.'}.get(c,None) or
chr(97+(ord(c)-83)%26) for c in ",adym,*)&uzq^zqf" ] )


More information about the Tutor mailing list