Way OT: HTML script

This appears to be one of the more IT literate groups that I subscribe to, and I've no idea where I should be asking, so....

I want a cron-like script (to run on XP Pro) that will periodically login to a web page (my router's admin function[1]) and copy part of the content of a specific table cell and append it (and current date and time) to the end of a local text file.

The layout of the page is fixed - the section I'm interested in looks like this:

Noise Margin

24 dB 13.5 dB

I'm after a text file that contains:

200410051130 13.5 200410051230 12 200410051330 14 200410051430 10.5 200410051530 6 etc.

Can anyone point me in the direction of a script/utility/function/freeware that'll do this kind of thing?

TIA.

[1] The data I want doesn't appear to be available via SNMP :(
Reply to
Grant
Loading thread data ...

If you can find a program/script to do the searching, you can get CronNT (not the one that ships with MS rescource kits) to do the scheduling if you google. The one I'm thinking of runs as a service on NT systems and uses a standard crontab file to run.

Perl on windows should be able to search the web page too.

Reply to
Sleeker GT Phwoar

Ta.

The cron behaviour is probably the easy bit. I guessed an answer to the screen scrape bit would probably involve Perl but anyone who's ever seen my code knows that's isn't going to happen this side of the millennium. Hoped there might be a pre-packaged solution out there.....

Reply to
Grant

Well, if you go and install Perl from here (easy to install, just accept the defaults for everything!):

formatting link
then put the following code into a file called, say, stats.pl:

##### start code #####

# --- VARIABLES --- #

# url to stats page - replace user & pass with the router username & password my $url = 'http://user:password@192.168.0.1/setup.cgi?next_file=stattbl.htm'; # output file my $log = 'd:/router-stats.txt';

# --- PROGRAM --- #

# connect to router and get raw html use LWP::UserAgent; my $ua = new LWP::UserAgent; my $req = HTTP::Request->new(GET => $url);my $response = $ua->request($req);my $html = $response->content; # get date/time & format my ($sec, $min, $hour, $mday, $mon, $year) = localtime(time()); my $dt = sprintf("%04d%02d%02d%02d%02d",1900+$year,$mon+1,$mday,$hour,$min);

# extract statistic $html =~ s/(\s|\n)+//g; my($stat) = $html =~ m!NoiseMargin[^&]+ dB([^&]+)!;

# print to file open(FH,">>$log"); print FH "$dt $stat\n"; close(FH);

##### end code #####

then change the $url and $log variables accordingly. (Note forward slash in path to stats file is deliberate and take care to preserve the format of the url)

then setup windows task manager to run "c:/perl/bin/perl.exe d:/whereeveryouputtheperlscript/stats.pl" (assuming perl installed to drive c:)

that should then work providing the html code you gave is exact, and providing you don't bugger up the syntax anywhere in the code, url, etc

:-)

Bigus

Reply to
Bigus

Had that already for MRTG...

Woohoo!

If you have a paypal account, let me know the email address and I'll gladly buy you a non-virtual pint. Ignore my reply-to, use urcm at grantm.clara.co.uk.

Reply to
Grant

In article , snipped-for-privacy@noisyfan.com spouted forth into uk.rec.cars.modifications...

I knew Perl would be the quick way, but I never thought anyone would knock up the answer so quickly.

Reply to
Sleeker GT Phwoar

cool.. glad you got it working

thanks for the offer, but a virtual pint will do :)

Bigus

Reply to
Bigus

MotorsForum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.