我正在尝试使用 python3 和 beautifulsoup4 为我的学校项目提取数据
I'm trying to use python3 and beautifulsoup4 to pull data for my school project
我有很多 类,名字是 marginBegin
。我想在整个代码中找到日期。
HTML代码:
<div class="marginBegin">
<dl>
<dt><label>Delivered On:</label></dt>
<!--fsrHiddenBlockStart--><dd><!--fsrHiddenBlockStart-->
Friday, 06/17/2016
at 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))
我有很多 类,名字是 marginBegin
。我想在整个代码中找到日期。
HTML代码:
<div class="marginBegin">
<dl>
<dt><label>Delivered On:</label></dt>
<!--fsrHiddenBlockStart--><dd><!--fsrHiddenBlockStart-->
Friday, 06/17/2016
at 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))