Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/perl -w
- use LWP;
- use HTTP::Cookies;
- use HTML::LinkExtor;
- use HTML::Entities;
- $argc = $#ARGV +1;
- if ($argc < 1)
- {
- die "URL needed";
- }
- else
- {
- $url = $ARGV[0];
- }
- #######################
- $browser = LWP::UserAgent->new;
- $browser->agent("Mozilla/5.0");
- $cooooooookie = HTTP::Cookies->new(
- file => 'delicious.file.is.a.cookie',
- # where to read/write cookies
- autosave => 1,
- ignore_discard => 1,
- # save it to disk when done
- );
- $browser->cookie_jar($cooooooookie);
- push @{ $browser->requests_redirectable }, 'POST';
- $response=$browser->get($url);
- #
- if ($url =~ m/^http:\/\/([a-z]+)\.?([a-zA-Z0-9]+)\.[a-z]+\/([a-zA-Z0-9~]+)/)
- {
- $file = "$1.inf";
- }
- else
- {
- die "Error";
- }
- if (-e $file)
- {
- #login($url);
- ;
- }
- else
- {
- open INF, ">$file" or die $!;
- createUser($url);
- print INF 'test11212@mail.com=guen1013';
- close INF;
- }
- #get all links on site
- my ($pageParser) = HTML::LinkExtor->new(undef, $url);
- $pageParser->parse($response->content())->eof;
- @links = $pageParser->links;
- #find all products on site
- @products = ();
- foreach $link(@links)
- {
- #check if link is a product
- if("$$link[2]" =~ /products_id/)
- {
- #add link to product array
- push(@products,$link);
- }
- }
- #choose a random product to buy
- $numberOfLinks = @products;
- $ranNum = RandomNum($numberOfLinks);
- $purProduct = $products[$ranNum];
- $productUrl = "$$purProduct[2]";
- print "This is my product $productUrl\n";
- # buy the product
- buy($productUrl);
- ###########################
- # Random number generator
- ###########################
- sub RandomNum
- {
- $range = $numberOfLinks-1; #number of products
- $randomNumber = int(rand($range));
- return $randomNumber;
- }
- ###########################
- # Create user account
- ###########################
- sub createUser
- {
- #$pageUrl = $ARGV[0];
- $response = $browser->get($url . '/index.php?main_page=login');
- print "login/checkout = ".$response->status_line."\n";
- $response=$browser->post($url . '/index.php?main_page=create_account',
- [
- 'action' => 'process',
- "gender" => "f",
- "zone_country_id" => "223",
- "firstname" => "My",
- "street_address" => "1234 My Street",
- "city" => "Mycity",
- "state" => "CA",
- "postcode" => "55555",
- "password" => "guen1013",
- "telephone" => "5555555555",
- "dob" => "01/20/1909",
- "lastname" => "Test",
- "email_address" => 'test11212@mail.com',
- "confirmation" => "guen1013",
- ]
- );
- print $response->status_line."\n";
- #print $response->content."\n";
- }
- ###########################
- # Login
- ###########################
- sub login
- {
- #login
- $page = $browser->get($url .'/index.php?main_page=login');
- $securityToken = 0;
- if($page->content =~ /securityToken" value="([a-z0-9]+)/)
- {
- $securityToken = $1;
- }
- print "This is the token $securityToken\n";
- $page = $browser->post($url .'/index.php?main_page=login&action=process&zenid='. $securityToken,
- [
- 'email_address' => 'test11212@mail.com',
- 'password' => 'guen1013',
- 'securityToken' => "$securityToken",
- ]
- );
- print $page->content;
- }
- ###########################
- # Buy product
- ###########################
- sub buy
- {
- $url = $ARGV[0];
- #get product information
- $response = $browser->get($productUrl);
- #$contents = $response->content();
- #get product ID
- if($productUrl =~ m/products_id=([0-9]+)/)
- {
- $prodID = $1;
- # $prodID = 117;
- }
- print "This is the ID $prodID\n";
- #get product price
- $price = 0.00;
- if( $response->content() =~ m/<title>(.*?)</)
- {
- $tempPrice = $1;
- }
- if($tempPrice =~ m/\$([0-9\.]+)/)
- {
- $price = $1;
- }
- print "The price is $price\n";
- #add product to cart
- #$response = $browser->get($url . '/index.php?main_page=product_info&cPath=22&products_id=' . "$prodID" . '&number_of_uploads=2&action=add_product');
- $response = $browser->post($url . '/index.php?main_page=product_info&cPath=22&products_id=' . "$prodID" . '&number_of_uploads=2&action=add_product',
- [
- 'cart_quantity' => '1',
- 'products_id' => "$prodID",
- ]
- );
- login;
- #$response = $browser->get($url . '/index.php?main_page=shopping_cart');
- #$response = $browser->post($url . '/index.php?main_page=shopping_cart',[]);
- #print $response->status_line."\n";
- #finish check out
- #check out step 1
- #$page = $browser->get($url . '/index.php?main_page=checkout_shipping');
- $page = $browser->post($url . '/index.php?main_page=checkout_shipping',
- [
- "shipping" => "storepickup_storepickup",
- "action" => "process"
- ]
- );
- #check out step 2
- $page = $browser->post($url . '/index.php?main_page=checkout_payment',
- [
- "payment" => "cod",
- ]
- );
- #check out step 3
- $page = $browser->post($url . '/index.php?main_page=checkout_confirmation', []);
- #print $page->status_line . "\n";
- # print $page->content;
- }
Add Comment
Please, Sign In to add comment