Computing.Net > Forums > Programming > Parsing HTML with batch

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Parsing HTML with batch

Reply to Message Icon

Name: tonysathre
Date: July 17, 2007 at 08:01:04 Pacific
OS: Windows XP Pro SP2
CPU/Ram: P4 2.60 Ghz\ 768 MB
Product: Dell Dimension 4550
Comment:

At work we are constantly installing AVG Free for customers on there computers. I would like to keep the a local copy of the latest build on our file server. The site does not have static links to the latest build. I want to use wget to download the file. How with a batch script can I parse the HTML, or the page itself to get the link to the latest version?
Here is the page.

"Computer security." — Oxymoron



Sponsored Link
Ads by Google

Response Number 1
Name: ghostdog
Date: July 17, 2007 at 16:31:12 Pacific
Reply:

The file name has a fixed pattern before the underscore so you can use that. As for the latest version, you can use the time stamp. Forget about using batch to parse HTML. Use more useful tools like perl/python that makes your job easier


0

Response Number 2
Name: Razor2.3
Date: July 17, 2007 at 20:20:13 Pacific
Reply:

Yeah, the <'s and the >'s make parsing in batch near impossible. If you want to stay with native scripting languages in Windows, you'll have to use JScript or VBScript. If you just want the easiest parsing language, go with Perl. After all, Perl grew out of the text parsing language, AWK.


0

Response Number 3
Name: Mechanix2Go
Date: July 18, 2007 at 05:38:48 Pacific
Reply:

This is hardwired to get the latest avg75amwt*.exe ; you can tailor the FIND line to suit.


::==
:: get AVG.bat :: gets latest avg75amwt*.exe

@echo off
setLocal EnableDelayedExpansion

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

wget http://download.grisoft.cz/filedir/...

find "avg75amwt" < 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 http://download.grisoft.cz/filedir/...

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

Yes, boys and girls, I know it's a kludge.


=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 4
Name: Mechanix2Go
Date: July 18, 2007 at 06:13:53 Pacific
Reply:

well... almost

Add the following line to clear out old index files BEFORE the first wget:

if exist index*.* del index*.*



=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 5
Name: tonysathre
Date: July 18, 2007 at 11:45:49 Pacific
Reply:

Thats awesome. Thanks a lot M2. I owe ya 3.

"Computer security." — Oxymoron


0

Related Posts

See More



Response Number 6
Name: tonysathre
Date: July 20, 2007 at 10:40:28 Pacific
Reply:

For any other techs out there, here's the final script:

::==getAVG.bat
:: Gets the latest version of AVG Free Edition
::
:: Requirements: wget.exe Win32
:: Windows NT/2000/XP
::
::@echo off
:start
setLocal EnableDelayedExpansion

:: Set version
set ver=75

:: Get old version
for /f "tokens=*" %%i in ('dir /b ^| findstr /i "avg75"') do (
set old_ver=%%i
)

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

if exist index*.* (
del index*.*
)

wget http://download.grisoft.cz/filedir/...

find "avg%ver%free" < 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
)

if exist !AVG! (
goto :cleanup
) else (
goto :wget
)

:wget
wget http://download.grisoft.cz/filedir/...
if not exist !AVG! goto start

:cleanup
for %%f in (q r s t u v w x y z) do if exist %%f del %%f
del /f /q index*.*

:: Delete old version
del /f /q %old_ver%


"Computer security." — Oxymoron


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Parsing HTML with batch

del a reg key value with batch www.computing.net/answers/programming/del-a-reg-key-value-with-batch/9246.html

Create a registry backup with batch www.computing.net/answers/programming/create-a-registry-backup-with-batch/8549.html

Help With Batch Programming www.computing.net/answers/programming/help-with-batch-programming/9667.html