本文介绍了想使用excel vba在网站上选择按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用excel浏览网页。但网站不像正常网站那样使用ID(亚马逊,谷歌等)。该网站是。我如何选择预订演示按钮。我通常会使用getelementbyID,但我不知道该id。我也尝试过标签和类,但没有运气。
I want to use excel to navigate a webpage. yet the website doesn't use ID's like a normal site does (amazon,google,ect). the website is http://www.scoopmae.com/. how would i select the "book a demo" button. I would normally use getelementbyID, but i don't know the id. I've also tried tag and class but no luck.
Sub scoop()
Set objie = CreateObject("InternetExplorer.Application")
objie.Top = 0
objie.Left = 0
objie.Width = 1600
objie.Height = 900
objie.Visible = True 'We can see IE
On Error Resume Next
objie.navigate ("http://scoopmae.com")
Do
DoEvents
Loop Until objue.readystate = 4
Application.Wait (Now + TimeValue("0:00:02"))
'MsgBox ("wait")
'click button
'objie.document.getElementsById("scoop-sort").Click
x = objie.document.getElementsByClassName("a")
Cells(1, 2) = x
End Sub
推荐答案
p>我可以通过这样做访问按钮。
I can access the button by doing this.
Sub test()
Dim oHtml As HTMLDocument
Dim oElement As Object
Set oHtml = New HTMLDocument
With CreateObject("WINHTTP.WinHTTPRequest.5.1")
.Open "GET", "http://www.scoopmae.com/", False
.send
oHtml.body.innerHTML = .responseText
End With
Set mybtn = oHtml.getElementsByClassName("sf-button large orange default dropshadow")(0).getElementsByTagName("span")
i = 0
For Each oElement In mybtn
Debug.Print mybtn(i).innerText
i = i + 1
Next oElement
End Sub
确保您进入工具 - >参考,并添加对Microsoft HTML对象库[MSHTML.TLB]
的引用感谢
Miguel
Make certain that you go to Tools -> References and add a reference to the Microsoft HTML Object Library [MSHTML.TLB]ThanksMiguel
这篇关于想使用excel vba在网站上选择按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!