首页 > 解决方案 > 使用 Internet Explorer 发表 YouTube 评论

问题描述

我正在尝试使用 IE 视频链接评论 YouTube 视频,但评论框输入值和评论按钮代码给出错误(未设置对象变量(错误 91)

Sub test()

Application.ScreenUpdating = False
Dim ie As Object: Set ie = CreateObject("internetexplorer.application")
Dim i, lastRow As Long
Dim wb As Workbook: Set wb = ThisWorkbook
Dim ws As Worksheet: Set ws = wb.Worksheets("Sheet1")

ie.Visible = True


lastRow = ws.Range("A" & ws.Rows.Count).End(xlUp).Row


' On Error Resume Next

For i = 1 To lastRow
    ie.navigate ws.Cells(i, 1)

    Do While ie.readyState <> READYSTATE_COMPLETE
        Application.Wait (Now + TimeValue("0:00:10"))
    Loop

注释框输入值(未设置对象变量(错误 91)

        Dim iDOC As MSHTML.HTMLDocument: Set iDOC = ie.document
        iDOC.getElementsByTagName("div").Item("comment-simplebox-text").Value = "nice video"

注释框单击(未设置对象变量(错误 91)

     Dim doc_ele As MSHTML.HTMLDocument
      Dim doc_eles As MSHTML.IHTMLElementCollection: Set doc_eles = 
    iDOC.getElementsByTagName("button")


For Each doc_ele In doc_eles
If doc_ele.className = "style-scope ytd-commentbox style-primary size-default" Then
doc_ele.Click
Else
End If
Next
Next
MsgBox "done"
 ' ie.Quit
Application.ScreenUpdating = True
End Sub

标签: vbaweb-scraping

解决方案


推荐阅读