in reply to html parsing

my $req = HTTP::Request->new(GET => 'https://www.google.com'); $req->content_type('application/json'); my $res = $ua->request($req);

Please edit your post including the initialization of $ua:

use LWP; my $ua = LWP::UserAgent->new; my $req = HTTP::Request->new(GET => 'https://www.google.com'); $req->content_type('application/json'); my $res = $ua->request($req);

Thank you. You could get the contents of the <title> tag just using a regular expression

my $title; $res->content =~ m|<title>(.+?)</title>|i and $title = $1;

but see e.g. Re: Why this simple regex freeze my computer? for caveats.

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Replies are listed 'Best First'.
Re^2: html parsing
by Anonymous Monk on Mar 22, 2017 at 15:25 UTC
    "You could get the contents of the <title> tag just using a regular expression"

    Solutions that use regular expressions to parse HTML will never be voted higher than those that actually use a parser. Also your assignment is very low value because it explicitly uses $1 when you could have instead captured the value directly (and safer too).

      I'd downvote my answer, if I could, not only for the shameless plug.

      Also your assignment is very low value because it explicitly uses $1 when you could have instead captured the value directly (and safer too).

      Providing code for that end might significantly improve this subthread.

      perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
        I was hoping you would do that. :)
        (my $title) = $res->content =~ m|<title>([^<]+)</title>|i;
Re^2: html parsing
by bigup401 (Pilgrim) on Mar 22, 2017 at 19:53 UTC

    thanks guys, thanks shmem. your idea has worked for me