#!/usr/bin/perl use strict; use warnings; use LWP::UserAgent (); use Time::Piece; use XML::LibXML; # Retrieve XML my $ua = LWP::UserAgent->new(timeout => 5); $ua->ssl_opts(verify_hostname => 0); $ua->env_proxy; $ua->agent(''); my $a = 'https://www.perlmonks.org/?node_id=30175'; my $r = $ua->get($a); die $r->status_line if not $r->is_success; # Parse XML my $dom = XML::LibXML->load_xml(string => $r->decoded_content); # Print HTML representation of each node my $i; for my $node ($dom->findnodes('/NEWESTNODES/NODE')) { my $d = Time::Piece->strptime(($node->findnodes('./@createtime'))[0]->to_literal, '%Y%m%d%H%M%S')->strftime('%a, %e %B %Y %H:%M:%S UTC'); my $f = ($node->findnodes('./@authortitle'))[0]->to_literal; (my $s = $node->to_literal) =~ s/^\s+|\s+$//; next if $s eq $f; # Skip home nodes my $l = 'https://www.perlmonks.org/?node_id=' . ($node->findnodes('./@node_id'))[0]->to_literal; print <
Date: $d
From: $f
$s
HTML last if ++$i >= 5; }