无法在网站标签中选择标签<li>的子元素

时间:2018-03-29 20:55:09

标签: html vba excel-vba excel

我在Internet Explorer上使用以下VB代码来自动化门户网站:

Dim MyBrowser As InternetExplore
Dim MyHTML_Element As IHTMLElement
Dim myURL As String

Dim htmlInput As HTMLInputElement
Dim htmlColl As IHTMLElementCollection
Dim p As String
Dim link As Object
Dim I As Integer
Dim ie As SHDocVw.InternetExplorer
Dim doc As MSHTML.HTMLDocument

On Error GoTo Err_Clear
myURL = "url............."
Set MyBrowser = New InternetExplorer
MyBrowser.Silent = True
MyBrowser.navigate myURL
MyBrowser.Visible = True
Do
Loop Until MyBrowser.readyState = READYSTATE_COMPLETE
Set HTMLDoc = MyBrowser.Document

HTMLDoc.getElementsByTagName("a").Item(7).Click    <-----Error

Err_Clear:
  If Err <> 0 Then
  Err.Clear
  Resume Next
  End If

但它在突出显示的行上出现错误,下面是我的网站检查:

enter image description here 请指导我在哪里犯错,只需点击标签?谢谢

1 个答案:

答案 0 :(得分:1)

你应该把一个doevents放到你的页面加载循环中。

#create example data
a <- c(1, 1, 1, 2, 2, 2) #this is the subsetting variable in the example
b <- c(NA, NA, "B", NA, NA, "C") #max 1 non-NA value for each subset
c <- c("A", NA, NA, "A", NA, NA)
d <- c(NA, NA, 1, NA, NA, NA) #some subsets for some columns have all NA values

dat <- as.data.frame(cbind(a, b, c, d)) 

> desired output
  a b c    d
  1 B A    1
  2 C A <NA>

通过id获取li元素,然后获取子锚。

Do
    doevents 
Loop Until MyBrowser.readyState = READYSTATE_COMPLETE