I'm very new to Python. I'm attempting to scrape a website for information, mostly text, but I have encountered a problem with the date. It looks like this:
<time class="jlist_date_image" datetime="2015-04-02 14:30:12">Idag <span class="list_date">14:30</span></time>
What I want from this is "2015-04-02 14:30:12". My problem is its not text. Could anyone help me.
Thanks!
>>> from bs4 import BeautifulSoup
>>> s = '''<time class="jlist_date_image" datetime="2015-04-02 14:30:12">Idag <span class="list_date">14:30</span></time>'''
>>> soup = BeautifulSoup(s)
>>> for i in soup.findAll('time'):
if i.has_attr('datetime'):
print(i['datetime'])
2015-04-02 14:30:12
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With