按名称获取元素值 [英] get element value by name

查看:32
本文介绍了按名称获取元素值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的 HTML 页面中查找特定的文本值

I'm trying to find a specific text value in my HTML page

我正在尝试使用 GetElementsByName(因为它没有任何 ID)

I'm trying to use the GetElementsByName ( as it does not have any ID )

x = msgbox("Wait for page to load",64, "Job ID")
JobId = IE.Document.GetElementsByName("jobId")
x = msgbox((JobId.Value),64, "Job ID")

这是我要提取的 HTML 和值请帮忙谢谢!

here is the HTML and the value that I want to extract Please help THANKS !

推荐答案

Try x = msgbox((JobId(0).Value),64, "Job ID")

当您使用 GetElementsByName 标签时,它将返回一个数组.如果您只有一个带有该 name 标签的项目,您始终可以使用 JobID[0] 来引用它.

When you use the GetElementsByName tag, it will be returning back an array. If you only have one item with that name tag, you can always use JobID[0] to reference it.

但是,如果您要拥有多个项目,则必须进行某种循环

How ever if you are going to have more than one item, you will have to do some sort of loop

For Each job in JobID
  msgbox((job.Value),64, "Job ID")
Next

你也可以这样做

inputs = IE.Document.getElementsByTagName("input")
For Each input in inputs
  If input.type = "hidden" && input.name = "JobId" Then
     msgbox((input.Value),64, "Job ID")
  End If
Next

这篇关于按名称获取元素值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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