Last active
August 29, 2015 14:19
-
-
Save abuzarhamza/8b9b4d7d2c24f9ef414a to your computer and use it in GitHub Desktop.
youtube serach history
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
use strict; | |
use warnings; | |
use Getopt::Std; | |
use Selenium::Remote::Driver; | |
use Data::Dumper; | |
########################## | |
#u need to run selenium-server-standalone | |
#java -jar selenium-server-standalone-2.45.0.jar | |
# | |
# | |
########################### | |
usage() if ( scalar(@ARGV) < 1); | |
my %options = (); | |
getopts("he:p:", \%options) or usage(); | |
usage() if $options{h}; | |
my $user_login = $options{e} if defined $options{e}; | |
my $paswd = $options{p} if defined $options{p}; | |
my $driver= Selenium::Remote::Driver->new; | |
#get the youtube page | |
$driver->get('http://www.youtube.com'); | |
sleep(5); | |
#go the signin button | |
my $query = $driver->find_element("//button[\@class='yt-uix-button yt-uix-button-size-default yt-uix-button-primary']"); | |
$query->click; | |
sleep(2); | |
#find emailinput box | |
$query = $driver->find_element('Email','name'); | |
$query->send_keys($user_login); | |
#find password box | |
$query = $driver->find_element('Passwd','name'); | |
$query->send_keys($paswd); | |
#sign page | |
$query = $driver->find_element('signIn','name'); | |
$query->click; | |
sleep(2); | |
#get the aapmenu | |
$query = $driver->find_element_by_xpath("//button[\@aria-controls='appbar-guide-menu']"); | |
if ( $query ) { | |
$query->click; | |
} | |
sleep(2); | |
#hit the history button | |
$query = $driver->find_element("//a[\@data-external-id='history']"); | |
$query->click; | |
sleep(5); | |
#need to buttom of page lod more page | |
#while loop to load the page to the end | |
while ( 1 ) { | |
$query = $driver->find_element_by_xpath(q{//button[@class='yt-uix-button yt-uix-button-size-default yt-uix-button-default load-more-button yt-uix-load-more browse-items-load-more-button']}); | |
if ( $query =~ /^0$/ ) { | |
my $script = q{window.scrollTo(0,document.body.scrollHeight);}; | |
my $elem = $driver->execute_script($script); | |
sleep(5); | |
} | |
else { | |
my $script = q{window.scrollTo(0,document.body.scrollHeight);}; | |
my $elem = $driver->execute_script($script); | |
$query->click; | |
$script = q{window.scrollTo(0,document.body.scrollHeight);}; | |
$elem = $driver->execute_script($script); | |
sleep(5); | |
} | |
} | |
$driver->quit; | |
sub usage { | |
print STDERR << "EOF"; | |
usage: $0 [-he] [-p] | |
-h | |
example: $0 -h | |
example: $0 -e <gmail_email_id> -p <gamil_pasword> | |
EOF | |
exit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment