Excel getElementById提取span类信息 [英] Excel getElementById extract the span class information
问题描述
这是我从中单独提取位置信息的HTML。
< dl id =headlineclass =demographic-info adr>
< dt>位置< / dt>
< dd>
< span class =locality>
达拉斯/沃思堡区
< / span>
< / dd>
< dt>行业< / dt>
< dd class =industry>
高等教育
< / dd>
在我的excel VBA中打开网页,我使用以下代码来提取信息。
Dim openpage as String
openspage = iedoc1.getElementById(headline)。innerText
但是,我收到的信息是
位置达拉斯/沃思堡地区工业高等教育
我只需要提取
<强>达拉斯/沃斯堡区作为输出。
尝试: iedoc1.getElementById(headline)getElementsByTagName(span) ).innerText
你得到所有额外的文字,因为这是你所要求的,父元素的innerText,这是一切
上述代码获取headline元素的内容,然后在其中找到所有span标签。查看返回的列表,它选择第一个实例并返回innerText。
更新
我总是似乎得到索引基本错误,我的示例中的 1
应该是一个 0
I need to extract certain information from HTML using VBA.
This is the HTML from which I am trying to extract the location information alone.
<dl id="headline" class="demographic-info adr">
<dt>Location</dt>
<dd>
<span class="locality">
Dallas/Fort Worth Area
</span>
</dd>
<dt>Industry</dt>
<dd class="industry">
Higher Education
</dd>
In my excel VBA, after opening the web page, I am using the following code to extract the information.
Dim openedpage as String
openedpage = iedoc1.getElementById("headline").innerText
However, I am getting the information as,
Location Dallas/Fort Worth Area Industry Higher Education
I just need to extract,
Dallas/Fort Worth Area as the output.
Try: iedoc1.getElementById("headline").getElementsByTagName("span")(0).innerText
Your getting all the extra text because that is kinda what you asked for, the innerText of the parent element, which is everything inside of it.
The above code gets the content of the "headline" element, then finds all "span" tags inside of it. Looking at the list returned, it chooses the first instance and returns the innerText.
Update
I always seem to get the index base wrong, the 1
in my example should have been a 0
这篇关于Excel getElementById提取span类信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!