Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: html parsing

by shmem (Chancellor)
on Mar 22, 2017 at 15:11 UTC ( [id://1185464]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1185464]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-24 16:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found