简体   繁体   中英

VBA to Capture text between Tags

I am trying to extract data from a website using VBA in excel. 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)"

 <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

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

whereby OBJ is your DIV element

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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