хм. Тут такое дело… У меня есть доступ на SVN
Спустя 167 сек.
<?php
require_once 'code/vendors/Goutte/goutte.phar';
class Client extends Goutte\Client
{
public function requestPlain($method, $uri, array $parameters = array(), array $headers = array(), array $files = array(), array $server = array(), $changeHistory = true)
{
/**
* Calls a URI.
*
* @param string $method The request method
* @param string $uri The URI to fetch
* @param array $parameters The Request parameters
* @param array $headers The headers
* @param array $files The files
* @param array $server The server parameters
* @param Boolean $changeHistory Whether to update the history or not (only used internally for back(), forward(), and reload())
*
* @return Symfony\Components\DomCrawler\Crawler
*/
$uri = $this->getAbsoluteUri($uri);
$server = array_merge($this->server, $server);
if (!$this->history->isEmpty()) {
$server['HTTP_REFERER'] = $this->history->current()->getUri();
}
$server['HTTP_HOST'] = parse_url($uri, PHP_URL_HOST);
$server['HTTPS'] = 'https' == parse_url($uri, PHP_URL_SCHEME);
$request = new Symfony\Components\BrowserKit\Request($uri, $method, $parameters, $files, $this->cookieJar->getValues($uri), $server);
$this->request = $this->filterRequest($request);
if (true === $changeHistory) {
$this->history->add($request);
}
if ($this->insulated) {
$this->response = $this->doRequestInProcess($this->request);
} else {
$this->response = $this->doRequest($this->request);
}
$response = $this->filterResponse($this->response);
$this->cookieJar->updateFromResponse($response, $uri);
$this->redirect = $response->getHeader('Location');
if ($this->followRedirects && $this->redirect) {
return $this->crawler = $this->followRedirect();
}
return $response->getContent();
}
}
$cookieJar = new Symfony\Components\BrowserKit\CookieJar();
$cookieJar->set(Symfony\Components\BrowserKit\Cookie::fromString('__unam=***'));
$cookieJar->set(Symfony\Components\BrowserKit\Cookie::fromString('trac_auth=***'));
$cookieJar->set(Symfony\Components\BrowserKit\Cookie::fromString('trac_form_token=***'));
$cookieJar->set(Symfony\Components\BrowserKit\Cookie::fromString('trac_session=***'));
$client = new Client(array(), array(), null, $cookieJar);
$initialUrl = 'https://trac.***.***.***';
define('OUTPUT_DIR', './output');
function parsePage(Client $client, $url, $path = '')
{
$crawler = $client->request('GET', $url . $path);
$items = $crawler->filter('#dirlist tbody tr td.name a');
foreach ($items as $item) { // $item = DOMElement а не $crawler!!!
$href = $item->getAttribute('href');
if ('dir' == $item->getAttribute('class')) {
$func = __FUNCTION__;
$func($client, $url, $href);
} else {
$crawlerNew = $client->request('GET', $url . $href);
$href = $crawlerNew->filter('#altlinks')->filter('li.last a')->attr('href');
$content = $client->requestPlain('GET', $url . $href);
//TODO: сохранить $content в файл
}
}
}
parsePage($client, $initialUrl, '/projectname/browser');