in reply to extract URLs from text
use strict; use feature ':5.10'; use LWP::UserAgent; our $ua = LWP::UserAgent->new; $ua->max_redirect(10); my $uri = 'https://t.co/O4qjsxuCsV'; say expand($uri); sub expand { my ($short) = @_; my $long; my $response = $ua->get($short); if ($response->is_success) { my @redirects = $response->redirects(); if (@redirects) { $long = $redirects[$#redirects]->header('location'); } elsif ($response->header('refresh')) { $long = $response->header('refresh'); $long =~ s/0\;URL\=//; } return $long; } else { return $short; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: extract URLs from text
by marto (Cardinal) on Sep 08, 2023 at 15:53 UTC | |
|
Re^2: extract URLs from text
by Bod (Parson) on Sep 08, 2023 at 23:05 UTC |