Jens Jens - 8 months ago 29
Perl Question

How to find string in HTML response

I have written a script to login to a web page and print the response. Now I want to find a string in the HTML response, but I don't know how.

My current code:

use strict;
use warnings;
use LWP::UserAgent;

my $clientIP = "";
my $clientURL = "http://" . $clientIP . "/conf";

## User Agent (UA)
my $ua=LWP::UserAgent->new;

$ua->credentials($clientIP, 'Secure Area', 'user', 'pa$$word');

my $page = $ua->get($clientURL);
my $body = $page->content();
print $body;

Current print output from

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<a href="settings">Settings</a>
<a href="updateskin">Update skin</a>
<a href="updatesettings">Update settings</a>
<p>Software Solutions</p>

How can I find the version string and number in the response and write it to a variable?

The goal of the script is to get the version number and write it to a file.


Thanks for your help. The regular expression is the simplest solution.

# Remove all wordwraps
my $ver='unknown'; # Default version
print "\n" . $ver . "\n";