vba 从引用父标签的类名或 ID 的子标签中提取数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14509206/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 19:20:54  来源:igfitidea点击:

Pull data from child tags referring to class name or ID of parent tag

vbaexcel-vbaexcel

提问by Gomathi Sankar

I need to pull the message "message i've to retry" from below HTML tags

我需要从 HTML 标签下方提取消息“我必须重试”

<div id="m_7qo0yziAwqKk02Gud0IM" style="padding: 0px 0px 10px; width: 681px;" class="w-7qo0yziAwqKk02Gud0t9 moduleContent">
 <div id="ext-comp-1345" class=" x-panel" style="width: 681px;">
 <div class="x-panel-bwrap" id="ext-gen931">
 <div class="x-panel-body x-panel-body-noheader x-column-layout-ct" id="ext-gen932" style="width: 681px;">
 <div class="x-column-inner" id="ext-gen934" style="width: 681px;">
 <div id="ext-comp-1346" class=" x-panel diff-area diff-enabled x-column" style="font-size: 23px; width: 591px;">
 <div class="x-panel-bwrap" id="ext-gen936">
 <div class="x-panel-body x-panel-body-noheader" id="ext-gen937" style="width: 591px;">message i've to retry</div>
 </div>
 </div>
 <div id="ext-comp-1348" class=" x-panel x-column" style="padding: 4px 0px 4px 2px; font-size: 11px; color: rgb(160, 160, 160); width: 589px;">
</div>
 </div>
 </div>
 </div>
 </div>
 </div>

I'm using below VBA code to point till parent tag, but don't know how to point child tag to fetch the data.

我使用下面的 VBA 代码指向父标记,但不知道如何指向子标记来获取数据。

Dim IE As New InternetExplorer
Dim doc As HTMLDocument
Set doc = IE.document
IE.navigate "Site link"
Dim dd As Variant
dd = doc.getElementById("m_7qo0yziAwqKk02Gud0IM")

Could anyone lead me

谁能带领我

Thanks !

谢谢 !

回答by Gomathi Sankar

I've used below code to get the data,

我使用下面的代码来获取数据,

Dim finalout As Variant
Dim dd As HTMLObjectElement    
Set dd = doc.getElementById("m_7qo0yziAwqKk02Gud0IM") 'assign web elements to a HTML document object
finalout = dd.getElementsByClassName(" x-panel x-column")(2).innerText  'now we have a bunch of required webtags in dd, out of which get your data by using methods and proper syntax
MsgBox finalout

It worked for me. :-)

它对我有用。:-)