Created
August 3, 2015 05:06
-
-
Save ChatchaiJ/cd6d3534ccc2fccd0eec to your computer and use it in GitHub Desktop.
Check latest free ebook from packt pub.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w- | |
use strict; | |
use warnings; | |
use autodie; | |
my $URL = "https://www.packtpub.com/packt/offers/free-learning"; | |
my $CMD = "curl -s -S $URL"; | |
my ($match_title, $bookname) = (0, ""); | |
open C, "$CMD |" or die "Can't execute cmd '$CMD' : $!\n"; | |
while (<C>) { | |
if (/<title>Free Learning | PACKT Books<\/title>/) { | |
die "Title already matched!\n" if ($match_title == 1); | |
$match_title = 1; | |
next; | |
} | |
if (/<h2>$/) { | |
($bookname) = (<C> =~ /\s+(.+?)\s+\<\/h2/); | |
} | |
} | |
close C; | |
if ($match_title) { | |
print localtime . "\t$bookname\n"; | |
} else { | |
print localtime . "\t[failed to get bookname]\n"; | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment