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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.