Parsing HTML With Batch

March 11, 2013 at 12:26:23
Specs: Windows 7
Awesome work guys by guys in this post
This post
... but I need modifying this for according to my needs plz.

I have website it has timestamp in HH:MM AM/PM format.

So this is what is on my website.

Last Updated as of 2:14 pm March 11th

I would like to parse 2:14 PM and compare it(subtract it) with current timestamp.

cansomeone help me with this? Thanks

@echo off
setLocal EnableDelayedExpansion
set curTimestamp=%date:~7,2% %date:~3,3%_%date:~10,4%_%time:~0,2%_%time:~3,2%
FOR /F "TOKENS=*" %%A IN ('TIME/T') DO SET Now=%%A

for %%F in (q r s t u v w x y z) do if exist %%F del %%F

wget <a href="" target="_blank" rel="nofollow"></a>

find "Updated" < index.html > q

for /f "tokens=1-4 delims==" %%a in (q) do (
echo %%d >> r
for /f "tokens=2-3 delims=>" %%a in (r) do (
echo %%a %%b >> s
for /f "tokens=1-2 delims=<" %%a in (s) do (
echo %%a %%b >> t
for /f "tokens=1-2 delims=^/" %%a in (t) do (
echo %%a %%b >> u
for /f "tokens=1,3 delims= " %%a in (u) do (
echo %%b %%a >> v
for /f "tokens=1-4 delims=- " %%a in (v) do (
echo %%c %%b %%a %%d >> w
for /f "tokens=* delims= " %%a in (w) do (
set str=%%a
set str=!str:Jan=01!
set str=!str:Feb=02!
set str=!str:Mar=03!
set str=!str:Apr=04!
set str=!str:May=05!
set str=!str:Jun=06!
set str=!str:Jul=07!
set str=!str:Aug=08!
set str=!str:Sep=09!
set str=!str:Oct=10!
set str=!str:Nov=11!
set str=!str:Dec=12!
echo !str! >> x
sort < x > y
for /f "tokens=4 delims= " %%a in (y) do (
set AVG=%%a
echo wget
echo %curTimestamp%
ECHO %Now%
::for %%F in (q r s t u v w x y z) do if exist %%F del %%F

See More: Parsing HTML With Batch

Report •

March 11, 2013 at 19:22:59
I can kinda see what you're doing, but without the source-text (index.html, or at least the target-line "last updated"), I don't have enough information. I can say this: that batch sucks at dates/times, and vbscript handles them very smoothly:
dateadd ("h","2:14 PM", 3) (17:14)
datediff ("s","2:14 PM","9:02 PM") (24480 seconds)
datediff("h","2:14 PM March 11","9:02 PM 3/12") (31 hours)
in short, many formats are accepted/handled properly, although you would have to strip off the "st", "rd", "th", "nd" from the date or otherwise handle it. The AM/PM stuff is handled with no problem. And system-date needs dofw stripped off:
Mon 03/11/13 to: 03/11/13

here's a "front-end" I wrote a couple years ago that executes the date math:
'this is the most "geared up" version. see dd, dx, daa for earlier versions
set xin=wscript.stdin
set cout=wscript.stdout
dim y,x
set y=wscript.arguments
if a<1 then
end if
if a<1 then
wscript.echo "add/subtract two times or dates, or add/sub units to a time or date"
wscript.echo "usage: da [units] time_and-or_date1 time_and-or_date2||number_of_units"
wscript.echo "Units is one of : D w m h N s and if caps, default format output"
wscript.echo "d=days, w=weeks, m=months (applied to date), h=hours, n=minutes, s=secs (applied to time)"
wscript.echo "Units default to days for dates, minutes for times"
end if
'use colon to interpret as time, else date
'sets defaults for date (adjust no. days) or time (adjust no. minutes)
if p>0 then
end if
'now allow overrides by token #1 if valid subset
if instr("dmwhns",lcase(y(0)))>0 then
'allow means for user to override formatting by using caps
if ucase(s)=s then ff=0
end if
if isnumeric(y(a)) then
end if

Report •
Related Solutions

Ask Question