简体   繁体   English

VBA捕获标记之间的文本

[英]VBA to Capture text between Tags

I am trying to extract data from a website using VBA in excel. 我正在尝试使用Excel中的VBA从网站中提取数据。 The page source has the following (below), and I can extract the text "This is my text" which is between the "A" tags, and I can extract everything that is between the "DIV" tags, which displays as " This is my text (XXXXX)" .....but I am unable to extract the block of text that just appears after the "/A"...eg "(XXXXX)" 页面源具有以下内容(如下),我可以提取“ A”标签之间的文本“ This is my text”,也可以提取“ DIV”标签之间的所有内容,显示为“ This是我的文本(XXXXX)” ....但是我无法提取仅在“ / A”之后出现的文本块...例如“(XXXXX)”

 <div style="padding: 1px;"><a href="#" onclick="if(typeof jsfcljs == 'function'){jsfcljs(document.getElementById('MainPage'),{'j_id32'},'');}return false">This is my text</a> (XXXXX)</div>

<div style="padding: 1px; padding-left:20px;"><a href="#" onclick="if(typeof jsfcljs == 'function'){jsfcljs(document.getElementById('MainPage'),{'j_id32'},'');}return false">This is my text</a> (XXXXXXXX)</DIV>

Any ideas?? 有任何想法吗??

If you know that the string you want is the one after the last tag closing inside your DIV element, use 如果您知道所需的字符串是DIV元素中最后一个标记关闭后的字符串,请使用

TXT = Right(OBJ.innerHTML, Len(OBJ.innerHTML) - InStrRev(OBJ.innerHTML, ">"))

whereby OBJ is your DIV element OBJ是您的DIV元素

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM