python 3.x - I'm trying to use python3 and beautifulsoup4 to pull data for my school project -


i have many classes having name marginbegin. want find date in whole code.

html code:

<div class="marginbegin">   <dl>     <dt><label>delivered on:</label></dt>     <!--fsrhiddenblockstart--><dd><!--fsrhiddenblockstart-->     friday, &nbsp;06/17/2016     at&nbsp;3:02 p.m.       <!--fsrhiddenblockend--></dd><!--fsrhiddenblockend-->   </dl> 

my result:

06/17/2016

i think work.

from bs4 import beautifulsoup import re soup = beautifulsoup(open("file.html")) link in soup.findall("div", { "class" : "marginbegin" }):     string= link.contents[1].findall("dd")     date=re.search(r'(\d+/\d+/\d+)',(str(string[0])))     print(date.group(1)) 

Comments