html - 动态站点上的 VBA Web 自动化
问题描述
我正在尝试从该站点删除条形码所有者:http: //gepir.gs1.org/index.php/search-by-gtin
由于最后一行,我收到“对象不支持此属性或方法”错误消息。我试图用类和标签提取它,但失败了。
我正在尝试从动态表中提取公司名称。
Sub aa()
Dim ie As New SHDocVw.InternetExplorer
Dim doc As HTMLDocument
Dim aaa As Object
Dim objIE As InternetExplorer
Set objIE = New InternetExplorer
ie.Visible = True
ie.navigate "gepir.gs1.org/index.php/search-by-gtin"
Do While ie.readyState <> READYSTATE_COMPLETE
Loop
Debug.Print ie.LocationName, ie.LocationURL
Set doc = ie.document
ie.document.forms("searchbygtin").elements("keyValue").Value = "685387379712"
ie.document.forms("searchbygtin").elements("method").Click
Debug.Print ie.document.getElementsBytag("tr")(7).innerText
End Sub
任何帮助都会很棒,谢谢
解决方案
你需要标签名
Debug.Print ie.document.getElementsByTagName("tr")(7).innerText
我得到了一个验证码,所以我怀疑你是否可以通过这种方式完成这项任务。Selenium 和 IE 似乎都触发了验证码,至少对我来说是这样。
如果不是验证码,我会按如下方式重写您的脚本(可能使用循环来确保存在 tr 元素):
Option Explicit
Public Sub GetLastChangeDate()
Dim ie As New SHDocVw.InternetExplorer, doc As HTMLDocument
Const URL = "gepir.gs1.org/index.php/search-by-gtin"
With ie
.Visible = True
.navigate URL
While .Busy Or .readyState < 4: DoEvents: Wend
Set doc = .document
Debug.Print .LocationName, .LocationURL
doc.getElementById("keyValue").Value = "685387379712"
doc.getElementById("submit-button").Click
While .Busy Or .readyState < 4: DoEvents: Wend
Debug.Print .document.getElementsByTagName("tr")(7).innerText
End With
End Sub
推荐阅读
- c# - C# Discord.Net bot - 如何每 X 小时发布一次消息?
- python - 如何通过 pty 获得彩色外壳
- python-2.7 - Buto ImportError:没有名为 get_dns 的模块
- c# - 我的程序甚至没有执行安装的运行时包
- python - 尝试在圆形数组中实现一个可以顺时针和逆时针方向移动的指针
- python - 从 pickle 文件加载 XGBoost 模型。错误:“XGBClassifier”对象没有属性“use_label_encoder”
- angular - 使用 ng-Bootstrap 调用 Stacked Modals,其中 modals 用作组件
- json - 在火花中展平json字符串
- websocket - 用户定义的自定义推送通知
- python - Python 中的 XOR 运算符示例