Ram*_*esh 3 html vba dom getelementbyid getelementsbyname
我试图使用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>
Run Code Online (Sandbox Code Playgroud)
我想以下面的格式提取信息.
时间:2005年 - 2012年
大学名称:大学2
在我的VB脚本中,我有以下代码,它将整个信息作为单个变量提取.
Dim openedpage as String
openedpage = iedoc1.getElementById("profile-education").innerText
Run Code Online (Sandbox Code Playgroud)
但是,如果我在我的vb脚本中使用以下语句,我可以获得特定的跨度信息.
openedpage = iedoc1.getElementById("profile-education").getElementsByTagName("span")
(0).innerText
Run Code Online (Sandbox Code Playgroud)
上面的代码给出了Phd作为输出.但是,我事先不会知道总跨度,因此我不能简单地在代码中给出span(0)和span(1).另外,我想提取所有div标签的信息,我也不会知道这些信息.基本上,我想要一些循环结构来迭代div标签和id profile-education,从中我应该能够提取多个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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16562 次 |
| 最近记录: |