我试图使用Vb脚本从HTML页面提取信息。这是我试图从中提取信息的HTML页面。
<div id="profile-education">
<div class="position first education vevent vcard" id="xxxxxx">
University 1
<span class="degree">Ph.D.</span>
<span class="major">Computer Science</span>
<p class="period">
<abbr class="dtstart" title="2005-01-01">2005</abbr> – <abbr class="dtend"
title="2012-12-31">2012</abbr>
</div>
<div class="position education vevent vcard" id="xxxxxx">
University 2
<span class="degree">M.Eng.</span>
<span class="major">Computer Science</span>
<p class="period">
<abbr class="dtstart" title="2000-01-01">2000</abbr> – <abbr class="dtend"
title="2004-12-31">2004</abbr>
</p>
</div>
</div>
我想以下面的格式提取信息。
- 大学名称:大学1
- 学位名称:Phd 专业:计算机科学
期间:2005 - 2012
大学名称:University 2
- 学位名称:M.Eng 专业:计算机科学
- 期间:2000 - 2004
在我的VB脚本中,我有以下代码,其中提取整个信息作为单个变量。
Dim openedpage as String
openedpage = iedoc1.getElementById("profile-education").innerText
然而,如果我在vb脚本中使用以下语句,我可以获得特定的span信息。
openedpage = iedoc1.getElementById("profile-education").getElementsByTagName("span")
(0).innerText
上面的代码给了我Phd作为输出。但是,我事先不知道总跨度,因此我不能简单地在代码中给出span(0)和span(1)。此外,我想提取所有div标签的信息,我也不会知道这个信息。基本上,我想要一些循环结构来迭代id为profile-education的div标记,我应该能够从中提取多个div和span信息。
Dim divs, div
set divs = iedoc1.getElementById("profile-education").getElementsByTagName("div")
for each div in divs
debug.print "*************************************"
debug.Print div.ChildNodes(0).toString
debug.print div.getElementsByTagName("span")(0).innerText
debug.print div.getElementsByTagName("span")(1).innerText
' etc...
next div