selenium-tor/README.md

1.5 KiB

Selenium Tor Implementation for facebook/php-webdriver

Usage

Install Composer

  • curl -SsL https://getcomposer.org/installer|php
  • mv composer.phar /usr/local/bin/composer

Get the code

  • Clone the repository git clone https://repos.bgemi.net/sikofitt/selenium-tor
  • cd selenium-tor

Install dependencies

  • Then install the dependencies with composer install

Get tor if you don't have it

  • composer download or
  • bin/console tor:download
use Sikofitt\WebDriver\FirefoxBinary;
use Sikofitt\WebDriver\Remote\DesiredCapabilities;
use Sikofitt\WebDriver\Tor\TorProfile;
use Sikofitt\WebDriver\TorLauncher;


require 'vendor/autoload.php';

$firefoxBinary = new FirefoxBinary(__DIR__ . '/../tor-browser_en-US/Browser/start-tor-browser');
$caps = DesiredCapabilities::tor($firefoxBinary);
$profile = new TorProfile();
$caps->setCapability('timeout', 3600);
$caps->setCapability(FirefoxDriver::PROFILE, $profile);

$torProcess = TorLauncher::launch($firefoxBinary);
// Wait for Tor to connect
sleep(2);
$webDriver = RemoteWebDriver::create('http://localhost:4444/wd/hub', $caps);
$webDriver->navigate()->to('http://32b5oz2bbtn6gqj3.onion');
// Or $this-webDriver->get('http://32b5oz2bbtn6gqj3.onion');
$pageImages = $webDriver->findElements(WebDriverBy::tagName('img'));
$images = [];
foreach($pageImages as $image)
{
    $images[] = $image->getAttribute('src');
}
TorLauncher::stop($torProcess);

Tests

composer test'