在 VBA 中获取属性值
我需要制作一个 VBA 文件来读取网页并返回 IMG 标签的 SRC 属性的值。我无法完成最后一步。你们能帮我吗?
<html>
<body>
<img src="image.jpg">
</body>
</html>
===编辑=== 我设法返回属性对象。现在我需要返回它的值
Option Compare Database
Sub AcessaPagina()
Dim ie As InternetExplorer
Dim test As String
Dim obj As Object
Set ie = New InternetExplorer
ie.Navigate "http://www.google.com.br"
MsgBox ie.Document.getElementsByTagName("img").Item(0).Attributes("src")
ie.Visible = True
End Sub
这就是我现在所拥有的。
I need to make a VBA file that will read a webpage and return the value of the SRC attribute of the IMG tag. I wasn't able to make the last step work. Can you guys help me?
<html>
<body>
<img src="image.jpg">
</body>
</html>
===Edit===
I managed to return the attribute object. Now I need to return its value
Option Compare Database
Sub AcessaPagina()
Dim ie As InternetExplorer
Dim test As String
Dim obj As Object
Set ie = New InternetExplorer
ie.Navigate "http://www.google.com.br"
MsgBox ie.Document.getElementsByTagName("img").Item(0).Attributes("src")
ie.Visible = True
End Sub
That's what I have at the moment.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有名为“getElementByTagName”的方法 - 它称为 getElementsByTagName (注意 s,因为它是一个集合)
文档对象返回文档对象中所有 img 标签的集合。来源。所以你可以像这样迭代它:
There is no method called "getElementByTagName" -- it's called getElementsByTagName (note the s because it is a collection)
The Document Object returns a collection of all the img tags in the source. So you can iterate it like this: