我正在尝试使用 python3 和 beautifulsoup4 为我的学校项目提取数据



我有很多类名字是marginBegin。我想在整个代码中找到日期。

HTML代码:

<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>
我结果:

06/17/2016

我想这可以。

from bs4 import BeautifulSoup
import re
soup = BeautifulSoup(open("file.html"))
for 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))

最新更新