Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^3: BBC4 Radio Schedules and LWP:UserAgent problem

by hippo (Bishop)
on Apr 07, 2018 at 16:43 UTC ( [id://1212494]=note: print w/replies, xml ) Need Help??


in reply to Re^2: BBC4 Radio Schedules and LWP:UserAgent problem
in thread BBC4 Radio Schedules and LWP:UserAgent problem

I do not understand the implication of your comment "That way your code will run without many of the SSL-specific dependencies."

So, LWP::UserAgent is there to give you a client for accessing web resources which may be reached either via HTTP or HTTPS. The latter requires SSL (or TLS) and those require lots of extra code in the form of crypto libraries and so forth. That's what your error message is talking about. If the only web resources you are trying to access are over HTTP then you don't need those extra libraries, modules and so on. Note that I'm grossly simplifying here to keep it understandable.

However, while the sample code you provided lists only an HTTP URL, mr_ron has pointed out that this merely redirects to an HTTPS URL and therefore you do in fact need all the extra code in order to get to the end resource which requires HTTPS. Still with us?

Now, here's some sample code using the real, end-point URL explicitly:

#!/usr/bin/env perl use strict; use warnings; use LWP::UserAgent; my $url = 'https://www.bbc.co.uk/radio4/programmes/schedules/fm/2015/1 +0/13'; my $ua = LWP::UserAgent->new (); my $res = $ua->get( $url ); my $html = $res->content; print substr ($html, 0, 256) . "...\n";

which produces this output:

$ perl getr4.pl <!DOCTYPE html> <html class="b-header--black--white b-footer--black--white " lang="en- +GB"> <head> <meta charset="UTF-8"> <title>BBC Radio 4 FM - Schedules, Tuesday 13 October 2015</ti +tle> <link rel="icon" href="https://www.bbc.c... $

This is using perl 5.20.3 and LWP::UserAgent 6.15, Mozilla::CA 20141217, LWP::Protocol::https 6.06, There are alternatives, but you can start with these. Try installing suitably recent versions of these modules using the documentation you have already read. You may need to install other dependencies too. Good luck.

Replies are listed 'Best First'.
Re^4: BBC4 Radio Schedules and LWP:UserAgent problem
by Anonymous Monk on Apr 07, 2018 at 21:16 UTC
    Thank you for that.
    I have been looking more at the example which failed because LWP::Protocol::https module is required.
    This failure message is only given when the final line of trying to print $html is included in the Perl.
    $html is set equal to $res->content. Printing the variable $res I get the text HTTP::Response=HASH(0x54d8608)

    As I only want to read the contents of the original web page, can I simply read the 'content' and therefore store the data in a hash? If so how is this done?

    If this can be done if may mean I do not have to find out how to install the missing modules and their dependencies.

      Run this script and post the output to show which OS, perl and module versions you have

      #!/usr/bin/perl use strict; use warnings; print grep /buil/i,qx(perl -v); print grep /buil|osname|uname|compile/i,qx(perl -V); printf "OS = %s\nPerl = %s\n\n",$^O,$^V; my @modules = qw(LWP::UserAgent LWP::Protocol::https Mozilla::CA); for my $mod (@modules){ if ( eval "use $mod;1" ) { no strict 'refs'; printf "%-20s = %s\n",$mod,${$mod.'::VERSION'}; } else { print "ERROR $@"; } } print join "\n",'','@INC = ',@INC;
      update 1 using eval update 2 added Mozilla:CA
      poj

Log In?
Username:
Password:

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

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

    No recent polls found