Extract dates using BeautifulSoup 4

beautifulsoup, python, python-2.7

Solution

Take the parent element of those divs, then get the three strings and join them into one string:

date = ' '.join([unicode(t) for t in parent.stripped_strings])

which would result in `Dec 31 Mon`.

If you need to manipulate the date, you'll need to parse it out to a `datetime.date` object; I strongly suggest you use the `dateutil` external library to do that. However, since the year is missing from this date, your mileage may vary.

Problem

how to extract the date in this using BeautifulSoup? ``` <div class="month"> Dec </div> <div class="edate"> 31 </div> <div class="day"> Mon </div ```

Original source