2016-12-20 14:32:00 -08:00
|
|
|
## Selenium Tor Implementation for [facebook/php-webdriver](https://github.com/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`
|
|
|
|
|
|
|
|
```php
|
|
|
|
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);
|
2016-12-22 12:24:54 -08:00
|
|
|
$webDriver = RemoteWebDriver::create('http://localhost:4444/wd/hub', $caps);
|
|
|
|
$webDriver->navigate()->to('http://32b5oz2bbtn6gqj3.onion');
|
2016-12-20 14:32:00 -08:00
|
|
|
// Or $this-webDriver->get('http://32b5oz2bbtn6gqj3.onion');
|
2016-12-22 12:24:54 -08:00
|
|
|
$pageImages = $webDriver->findElements(WebDriverBy::tagName('img'));
|
2016-12-20 14:32:00 -08:00
|
|
|
$images = [];
|
|
|
|
foreach($pageImages as $image)
|
|
|
|
{
|
|
|
|
$images[] = $image->getAttribute('src');
|
|
|
|
}
|
|
|
|
TorLauncher::stop($torProcess);
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
### Tests
|
|
|
|
|
|
|
|
`composer test'`
|