vba - 使用 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
解决方案
推荐阅读
- flutter - Flutter:应用程序在加密时卡住
- domain-driven-design - 订阅是遵循 ddd 原则的域的一部分吗?
- ros - 离线安装 ROS Melodic
- javascript - 如何创建 javascript 数组并将另一个数组数据保存到 Javascript 中创建的数组
- elasticsearch - 发送脚本调用请求时,将 Data Raw 内容移动到 URL
- cakephp - CakePHP 4 - 自定义请求和响应格式
- hadoop - 辅助名称节点无法启动 ssh:连接到主机 0.0.0.7 端口 22:连接超时
- java - API 30 中的透明状态栏
- .net - 获取 IISAppPool | .NET 中的选择对象状态为空
- date - 具有短时区 ID 的 hive 时区转换