gpt4 book ai didi

vba - 在 Excel VBA 中使用 getElementsByClassName

转载 作者:行者123 更新时间:2023-12-02 17:56:55 25 4
gpt4 key购买 nike

下面是我正在使用的代码,但我收到此错误:

object doesn't support this property or method

使用getElementsByClassName时。我正在使用的新 2 变量没有被填充,请帮助我,如果我做错了,请告诉我。

Sub PopulateTasks()
'Variable Declaration
Dim ie As Object
Dim noTaskText As String
Set ie = CreateObject("InternetExplorer.Application")

url = "http://example/do/"
.Visible = True
.Navigate url
.Top = 50
.Left = 430
.Height = 400
.Width = 400
Do Until Not ie.Busy And ie.readystate = 4
DoEvents
Loop
End With
Set link = ie.Document.getElementsByTagName("a")

For i = 1 To 200
For Each l In link
If l.innertext = storyIds(i) Then
l.Click
Do Until Not ie.Busy And ie.readystate = 4
DoEvents
Loop
If InStr("No tasks have been defined.", ie.Document.Body.outerText) <> 0 Then
noTaskFound = True
End If
noTaskText = ie.Document.getElementsByClassName("highlighted_message")(0).innerText

If noTaskFound = True Then

End If
Next
ie.Document.getElementbyId ("")
Do Until Not ie.Busy And ie.readystate = 4
DoEvents
Loop
Next i
End Sub

最佳答案

要获取具有类名的元素,我将使用 querySelector:

Set element = ie.Document.querySelector(".classname")
Debug.Print element.innerHTML

以你的例子:

txt = ie.Document.querySelector(".highlighted_message").innerText
If txt = "No tasks have been defined." Then
noTaskFound = True
Exit For
End If

关于vba - 在 Excel VBA 中使用 getElementsByClassName,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35974796/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com