Advertisement
Quantumzblue

aliexpress get infomation

Aug 8th, 2018
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 5.40 KB | None | 0 0
  1. # version 1.1 need to add description item and the shipping times
  2.  
  3. #!/usr/bin/perl -w
  4. use Data::Dumper;
  5. use HTTP::Cookies;
  6. use LWP::UserAgent;
  7. use LWP::Simple;
  8. use strict;
  9. $| =1;
  10.   my $browser;
  11.   my $htmlpage;
  12.   my $profitRate = 1.6;
  13. sub startBrowser{
  14.  
  15.    $browser = LWP::UserAgent->new(
  16.       agent=>'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/1.5.0.5',
  17.     #  cookie_jar => $cookie_jar,
  18.       max_redirect => 0,
  19.       timeout =>15,
  20.                                     );
  21. }
  22. sub getURL{
  23.  
  24.   my $url = $_[0];
  25.   my $resp = $browser->get($url);
  26.   my $content = $resp->content(); #make content store web scoure
  27.     #print $content;
  28.   return $content;
  29. }
  30.  
  31.  
  32.  
  33.  
  34.  
  35. sub getInfo{
  36.   my ($photoUrl,
  37.       $nameProduct ,
  38.       $description,
  39.       $shipingtime,
  40.       $dirName,
  41.       $minPrice,$maxPrice,$sellPrice,
  42.         );
  43.         $photoUrl =     'imageBigViewURL=\[\s+(\"[\w:\/\/\\.\-\"\,\s]+"\s+])';
  44.           $nameProduct  = 'product-name.*>(.*)<';
  45.           my @itemsOption = ('<span.*?>([\w\s]+)</span></a></li>', '.jpg"\s+title="([\w\s]+)"\s');
  46.             $minPrice = $htmlpage =~ /minPrice="(\d+.\d+)"/g; $minPrice = $1;
  47.             $maxPrice = $htmlpage =~ /maxPrice="(\d+.\d+)"/g; $maxPrice = $1;
  48.             $sellPrice = $maxPrice * ($profitRate + 0.1); # estimated fee + risk as 10% of selling prices.
  49.  
  50.       if ($htmlpage =~ /$nameProduct/){
  51.         $nameProduct = $1;  $dirName = $nameProduct =~ s/[\s\,]/\_/gr;
  52.         print "[+]The product:".$nameProduct."\n";
  53.         system("mkdir $dirName && cd $dirName && echo $nameProduct >> Product.txt && echo - >> Product.txt && echo minPrice:$minPrice  maxPrice:$maxPrice >> Product.txt && echo Sell@ :  $sellPrice >> Product.txt && mkdir images");
  54.       }  else { print "[-]Name product no found \n"; }
  55.  
  56.  
  57. if ( $htmlpage =~ /$itemsOption[0]/g ) {
  58.       my @choice = ($htmlpage =~ m/$itemsOption[0]/g );
  59.  
  60.       @choice[scalar(@choice)] = $htmlpage =~ /$itemsOption[0]/g;
  61.       my @reOrdre;
  62.       $reOrdre[0] = @choice[scalar(@choice)-1];
  63.       for (my $i =0; $i<scalar(@choice)-1;$i++) {
  64.          $reOrdre[$i+1] = $choice[$i];
  65.  
  66.  
  67.       }
  68.         foreach (@reOrdre) {     #span choices
  69.             print "[+] choices :";
  70.             print "$_ \n";
  71.             system("cd $dirName && echo $_ >> options.txt");
  72.  
  73.  
  74.  
  75.                                                               if ($htmlpage =~ /$itemsOption[1]/g )    {
  76.  
  77.                                                                       my @choice = ($htmlpage =~ m/$itemsOption[1]/ig );
  78.                                                                              @choice[scalar(@choice)] = $htmlpage =~ /$itemsOption[1]/g;
  79.                                                                              my @reOrdre;
  80.                                                                              $reOrdre[0] = @choice[scalar(@choice)-1];
  81.                                                                              for (my $i =0; $i<scalar(@choice)-1;$i++) {
  82.                                                                                 $reOrdre[$i+1] = $choice[$i];
  83.                                                                                                                       }
  84.                                                                                       foreach  (@reOrdre) {     #images choices
  85.                                                                                           print "[+] choices option:";
  86.                                                                                           print "$_ \n";
  87.                                                                                           system("cd $dirName && echo $_ >> options.txt");        }
  88.  
  89.  
  90.                                                                           }
  91.  
  92.              }    }
  93.  
  94.             elsif ($htmlpage =~ /$itemsOption[1]/ig) {
  95.               my @choice = ($htmlpage =~ m/$itemsOption[1]/ig );
  96.                @choice[scalar(@choice)] = $htmlpage =~ /$itemsOption[1]/g;
  97.                my @reOrdre;
  98.                $reOrdre[0] = @choice[scalar(@choice)-1];
  99.                for (my $i =0; $i<scalar(@choice)-1;$i++) {
  100.                   $reOrdre[$i+1] = $choice[$i];
  101.                                                         }
  102.                 foreach  (@reOrdre) {     #images choices
  103.                     print "[+] choices :";
  104.                     print "$_ \n";
  105.                     system("cd $dirName && echo $_ >> options.txt"); }
  106.  
  107.  
  108.                 }
  109.                     else {  print "[~][+]There is no choices \n"}
  110.  
  111.  
  112.  
  113.   if($htmlpage =~ /$photoUrl/)
  114.   {
  115.     $photoUrl = $1;
  116.     print $photoUrl;
  117.     print "Start collecting photos:\n";
  118.  
  119.     my @imageUrl = $photoUrl =~ /\"(.*.jpg)\"[,\s]/ig;
  120.     for (my $i = 0; $i < scalar(@imageUrl); $i++ ) {
  121.       print $imageUrl[$i]."\n";
  122.  
  123.     if (is_success(getstore($imageUrl[$i], $dirName.'\\images\\'.$i.'.jpg'))) {      # !!!!!!!!!!!!! warning won't download file if file directory no found !
  124.         print "Success\n";
  125.     } else { print "failed \n"; }
  126.  
  127.  
  128. }
  129.  
  130.   }
  131.     print "[+]finished \n";
  132.  
  133. }
  134.  
  135.  
  136. #============================================================================== start ============================================================
  137.  
  138. startBrowser();
  139. print "Link: ";
  140. chop (my $link = <stdin>);
  141. $htmlpage = getURL($link);
  142. #$htmlpage = getURL('');
  143. getInfo();
  144.  
  145.  
  146.  
  147.  
  148.  
  149. sleep();
  150. system("pause");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement