使用vba从span提取内部文本 [英] Extracting the inner text from span using vba

查看:204
本文介绍了使用vba从span提取内部文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用vba将网页中的某些数据抓取到Excel中.

I am trying to scrap some data from a webpage into Excel using vba.

html代码是

<span id="lastPrice">300.21</span>

我要电话号码300.21

I want the number 300.21

我尝试了这个但是没用(在st中没有返回任何内容)

I tried this but didn't work (returned nothing in st)

Dim st As String

st = htmldoc.getElementById("lastPrice").getElementsByTagName("span")(5).innerText

如何获得所需的输出?

推荐答案

尝试一下:

Dim element as Object
Set element = htmldoc.getElementById("lastPrice")

Dim price as String
If Not element Is Nothing Then price = element.innerText

这篇关于使用vba从span提取内部文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆