Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use regex and vbscript to work with nested tags

Status
Not open for further replies.

m2244

Programmer
Jun 5, 2013
11
0
0
US
Hello,

I have a script that is copying HTML files from one folder to another. I need to add to this script so that I can target a specific div '<div id="page_content_top_stage">' and grab all of the content in that div. The hard part is ignoring nested divs. In other words, the regex I have now will find the div I need but if there is a nested div tag, the regex stops at that inner '</div>' potentially missing a lot of needed content.

Is this something that can be done with regex and vbscript?

HTML code:
Code:
 <div id="page_content_top_stage"> <br><div></div>
      <!-- InstanceBeginEditable name="content up" -->
      <table border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td width="1" height="100%"><img src="../gui_assets/gui_images/spacer.gif" width="1" height="627"></td>
          <td width="740" valign="top"><img src="../gui_assets/gui_images/spacer.gif" width="740" height="1"><br>
          </td>
        </tr>
      </table>
      <!-- InstanceEndEditable --> </div>
 
Personally, I would use an HTA (HyperText Application) - an instance of IE that allows HTML DOM access). Other parsing options involve knowing the length of data your want to extract. This way, getting that content of that element is as "easy" as [tt]strContent = document.getElementById("page_content_top_stage")[/tt]. There is trade-off, though. You won't be able to direct use the wscript library.

I'd recommend doing a few searches on the topic but, generally, it's as easy as renaming an .HTM file .HTA and putting your code in between <script> tags.

-Geates

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top