Advertisement
ZaynerTech

Grab eBay Prices Fast and Easy

Mar 10th, 2013
1,326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.77 KB | None | 0 0
  1. #!/usr/bin/perl
  2. #
  3. # fast easy tool to grab prices from ebay and compare to sold prices of similar
  4. # or same items
  5. #
  6. # Usage: ./cheapfinds.pl <search term buying> <search term sold> <maximum buying price default 9999999>
  7. #
  8. # Searches in the ebay Health care Lab and Life Sciences category
  9. # can be changed easily by modifying he URLs below
  10. #
  11. # Default for search term sold is search term buying
  12. # only does first 200 items sorted by lowest price first
  13. # price includes shipping to zipcode 60615 change zipcode below
  14.  
  15. my %buy = ();
  16. my %sell = ();
  17.  
  18. $zipcode = 60615;
  19.  
  20. if(!$ARGV[0])
  21. {
  22.    print "Usage: ./cheapfinds.pl <search term buying> <search term sold> <maximum buying price default 9999999> \n";
  23.    print "Searches in the ebay Health care Lab and Life Sciences category \n";
  24.    print "can be changed easily by modifying he URLs in the code\n";
  25.    print "Zipcode default for shipping is 60615 change in code\n";
  26.    die;
  27. }
  28. if(!$ARGV[1]) { $ARGV[1] = $ARGV[0]; }
  29. if(!$ARGV[2]){ $ARGV[2] = 9999999; }
  30.  
  31. $search = $ARGV[0];
  32. $search =~ s/[^A-z0-9\-\s]\n\t//;
  33. $search =~ s/\s/+/g;
  34. $searchsold = $ARGV[1];
  35. $searchsold =~ s/[^A-z0-9\-\s]\n\t//;
  36. $searchsold =~ s/\s/+/g;
  37. $url[0] = "http://www.ebay.com/sch/i.html?_odkw=$search&_ipg=200&_sop=15&_osacat=11815&_from=R40&_nkw=$search&_sacat=11815&_clu=2&_fcid=1&_localstpos=$zipcode&_stpos=$zipcode&gbr=1";
  38. $url[1] = "http://www.ebay.com/sch/i.html?_odkw=$searchsold&_ipg=200&_sop=15&_osacat=11815&_from=R40&_nkw=$searchsold&_sacat=11815&_clu=2&_fcid=1&_localstpos=$zipcode&_stpos=$zipcode&gbr=1&LH_Complete=1&LH_Sold=1&rt=nc";
  39. $x = 0;
  40. $output[0] = "ebaybuy.html";
  41. $output[1] = "ebaysold.html";
  42.  
  43.  
  44. foreach $uri (@url)
  45. {
  46.  
  47. if($x == 0) {print "-----Selling-----\n"; }
  48. else { print "-----Already Sold-----\n"; }
  49.  
  50. #get webpages
  51. `/usr/bin/curl -s -A GoogleBot "$url[$x]" -o "$output[$x]"`;
  52.  
  53. #grep out info
  54. @title = `grep title= $output[$x] | grep -v hidden | grep -v Content`;
  55.  
  56. #parse out each item
  57. foreach $tit (@title)
  58. {
  59.   @name = split(/\=/, $tit);
  60.   @namesbetter = split(/\'/,$name[5]);
  61.    
  62.   if($namesbetter[1])
  63.   {
  64.     #find price and shipping
  65.     @parseprice = `grep -A 35 "$namesbetter[1]" $output[$x] | grep -A 15 price`;
  66.     foreach $p (@parseprice)
  67.     {
  68.       if($p =~ /\$/g)
  69.       {
  70.         $p =~ s/[^0123456789.]//g;
  71.         if($x == 0){  $buy{$namesbetter[1]} = $buy{$namesbetter[1]} + $p; }  
  72.         else { $sell{$namesbetter[1]} = $sell{$namesbetter[1]} + $p;}
  73.  
  74.       }
  75.     }
  76.   }
  77.  
  78.  
  79. }
  80.  
  81. #sort and output prices
  82. if($x == 0)
  83. {
  84.   foreach $key (sort {$buy{$a} <=> $buy{$b}} keys %buy)
  85.   {
  86.     if($buy{$key} <= $ARGV[2]){ print "$key : $buy{$key}\n";}
  87.   }
  88. }
  89. else
  90. {
  91.   foreach $key (sort {$sell{$a} <=> $sell{$b}} keys %sell)
  92.   {
  93.     print "$key : $sell{$key}\n";
  94.   }
  95. }
  96. print "\n\n";
  97. $x++;
  98.  
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement