I tried searching but couldn't find anything anything specific to what I need.
This is an excerpt from my HTML file:
<div id="pair_today">
<div class="left_block">
<div class="tpl_box">
<h1 style="margin-top:5px;color:#ec1b1b;">
<span style="font-size:15px;color:#000;">1 Australian Dollar =</span><br /> 93.663 Japanese Yen</h1>
<span style="display:inline-block; margin-top:10px; text-align:right; align:right; font-size:12px; color:#9c9c9c">rate on Fri, 6 March, 2015 15:58:20 (AEDT)</span>
<a href="http://fx-rate.net/AUD/JPY/currency-transfer/" title="Currenty Transfer from Australia to Japan" style="float:right" class="btn" onclick="ga('send','event', {'eventCategory': 'CurrencyTransfer', 'eventAction' : 'click','eventLabel':'Today Box'});"><span class="btn-ico btn-ico-go">Get Rate</span></a>
</span>
I need to parse out the 93.663 value from line 5. This value will be different every time I have to run the script, so I figured regex would be the best way to specifically target this value.
I've been tinkering with for /f loops but I don't know how to implement regex into the script.
Thanks guys!
Use Windows Scripting Host (VBscript or JScript). Use the
htmlfile
COM object. Parse the DOM. Then you can massage theinnerText
as needed with a regexp.Here you go. Save this as a .bat file, modify the
set "htmlfile=test.html"
line as needed, and run it. (Derived from this answer. Documentation for thehtmlfile
COM object in WSH is sparse; but if you would like to learn more about it, follow that bread crumb.)You know, as long as you're invoking Windows Script Host anyway, if you're acquiring your html file using wget or similar, you might be able to get rid of that dependency. Unless the page you're downloading uses a convoluted series of cookies and session redirects, you can replace wget with the
Microsoft.XMLHTTP
COM object and download the page via XHR (or as those with less organized minds would say, Ajax). (Based on fetch.bat.)