use strict use LWP my ua LWP UserAgent- new my page_url ARGV or print

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use strict;
use LWP;
my $ua = LWP::UserAgent->new;
my $page_url = $ARGV[0] or print "usage: perl downloadnum.pl page_url outfile\n" and exit;
$ua->default_header('Referer' => $page_url); # avito checks referer
#load page
my $page = $ua->get($page_url)->decoded_content;
# grep data
$page =~m/item_url = '(.*?)'/ or die "Can't find item_url!";
my $item_url = $1;
$page =~m/item_phone = '(.*?)'/ or die "Can't find item_phone!";
my $item_phone = $1;
$page =~m/id="item_id">(\d+)</ or die "Can't find item_id!";
my $item_id = $1;
# decode key
## keyDemixer() rewritten from js
my @pre = $item_phone=~m/[0-9a-f]+/g;
my $mixed = join '', ( ($item_id % 2 == 0) ? reverse @pre : @pre);
my $result ='';
for ( 0..(length($mixed)-1) ) {
if ( ($_ % 3) == 0) {
$result .= substr($mixed, $_, 1);
}
}
############
# get image
print $ua->get('http://www.avito.ru/items/phone/'.$item_url.'?pkey='.$result)->decoded_content;