how to extract the date in this using BeautifulSoup?
<div class="month"> Dec </div>
<div class="edate"> 31 </div>
<div class="day"> Mon </div
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.
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