请您帮助我从 - https://www.reliancepetroleum.com/locateafuelstation获取数据。这里必须为所有州提供下拉选择。我想每天提取所有州的下拉搜索结果。总共这个网站有22个州,我希望所有州的信息都在1个excel表中。请求您通过VBA代码或任何网络报废方法自动执行此操作。
答案 0 :(得分:0)
我已经对此进行了测试,它可以按预期的方式检索所有状态的数据,您只需修改行HTML.getElementById("storetab").innerText
即可从您希望的任何HTML元素中获取文本:
Enum READYSTATE
READYSTATE_UNINITIALIZED = 0
READYSTATE_LOADING = 1
READYSTATE_LOADED = 2
READYSTATE_INTERACTIVE = 3
READYSTATE_COMPLETE = 4
End Enum
Sub Test()
Dim ie As New InternetExplorer
Dim HTML As HTMLDocument
Dim i As Long
strURL = "https://www.reliancepetroleum.com/locateafuelstation"
ie.Visible = True
ie.navigate strURL
Do While (ie.Busy Or ie.READYSTATE <> READYSTATE.READYSTATE_COMPLETE)
DoEvents
Loop
Set HTML = ie.document
Set ctY = HTML.getElementById("idState")
NumberOfoptions = ctY.Options.Length
For i = 1 To NumberOfoptions
Set ctY = HTML.getElementById("idState")
Do While (ie.Busy Or ie.READYSTATE <> READYSTATE.READYSTATE_COMPLETE)
DoEvents
Loop
ctY.selectedIndex = i
HTML.getElementById("idBtnSubmit").Click
Do While (ie.Busy Or ie.READYSTATE <> READYSTATE.READYSTATE_COMPLETE)
DoEvents
Loop
Sheet1.Cells(i, 1).Value = HTML.getElementById("storetab").innerText
'ie.GoBack
ie.navigate strURL
Do While (ie.Busy Or ie.READYSTATE <> READYSTATE.READYSTATE_COMPLETE)
DoEvents
Loop
Next i
End Sub