Drupal 8.0.0 beta 12. More info: https://www.drupal.org/node/2514176
This commit is contained in:
commit
9921556621
13277 changed files with 1459781 additions and 0 deletions
3
core/vendor/fabpot/goutte/.gitignore
vendored
Normal file
3
core/vendor/fabpot/goutte/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
composer.lock
|
||||
phpunit.xml
|
||||
vendor
|
17
core/vendor/fabpot/goutte/.travis.yml
vendored
Normal file
17
core/vendor/fabpot/goutte/.travis.yml
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
language: php
|
||||
|
||||
php:
|
||||
- 5.6
|
||||
- 5.5
|
||||
- 5.4
|
||||
- hhvm
|
||||
|
||||
install:
|
||||
- travis_retry composer install --no-interaction --prefer-source
|
||||
|
||||
script:
|
||||
- phpunit
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- php: hhvm
|
171
core/vendor/fabpot/goutte/Goutte/Client.php
vendored
Normal file
171
core/vendor/fabpot/goutte/Goutte/Client.php
vendored
Normal file
|
@ -0,0 +1,171 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Goutte package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Goutte;
|
||||
|
||||
use GuzzleHttp\Client as GuzzleClient;
|
||||
use GuzzleHttp\ClientInterface as GuzzleClientInterface;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use GuzzleHttp\Message\RequestInterface;
|
||||
use GuzzleHttp\Message\Response as GuzzleResponse;
|
||||
use GuzzleHttp\Post\PostFile;
|
||||
use Symfony\Component\BrowserKit\Client as BaseClient;
|
||||
use Symfony\Component\BrowserKit\Response;
|
||||
|
||||
/**
|
||||
* Client.
|
||||
*
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @author Michael Dowling <michael@guzzlephp.org>
|
||||
*/
|
||||
class Client extends BaseClient
|
||||
{
|
||||
protected $client;
|
||||
|
||||
private $headers = array();
|
||||
private $auth = null;
|
||||
|
||||
public function setClient(GuzzleClientInterface $client)
|
||||
{
|
||||
$this->client = $client;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getClient()
|
||||
{
|
||||
if (!$this->client) {
|
||||
$this->client = new GuzzleClient(array('defaults' => array('allow_redirects' => false, 'cookies' => true)));
|
||||
}
|
||||
|
||||
return $this->client;
|
||||
}
|
||||
|
||||
public function setHeader($name, $value)
|
||||
{
|
||||
$this->headers[$name] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeHeader($name)
|
||||
{
|
||||
unset($this->headers[$name]);
|
||||
}
|
||||
|
||||
public function setAuth($user, $password = '', $type = 'basic')
|
||||
{
|
||||
$this->auth = array($user, $password, $type);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function resetAuth()
|
||||
{
|
||||
$this->auth = null;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function doRequest($request)
|
||||
{
|
||||
$headers = array();
|
||||
foreach ($request->getServer() as $key => $val) {
|
||||
$key = strtolower(str_replace('_', '-', $key));
|
||||
$contentHeaders = array('content-length' => true, 'content-md5' => true, 'content-type' => true);
|
||||
if (0 === strpos($key, 'http-')) {
|
||||
$headers[substr($key, 5)] = $val;
|
||||
}
|
||||
// CONTENT_* are not prefixed with HTTP_
|
||||
elseif (isset($contentHeaders[$key])) {
|
||||
$headers[$key] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
$body = null;
|
||||
if (!in_array($request->getMethod(), array('GET', 'HEAD'))) {
|
||||
if (null !== $request->getContent()) {
|
||||
$body = $request->getContent();
|
||||
} else {
|
||||
$body = $request->getParameters();
|
||||
}
|
||||
}
|
||||
|
||||
$this->getClient()->setDefaultOption('auth', $this->auth);
|
||||
|
||||
$requestOptions = array(
|
||||
'body' => $body,
|
||||
'cookies' => $this->getCookieJar()->allRawValues($request->getUri()),
|
||||
'allow_redirects' => false,
|
||||
'timeout' => 30,
|
||||
);
|
||||
|
||||
if (!empty($headers)) {
|
||||
$requestOptions['headers'] = $headers;
|
||||
}
|
||||
|
||||
$guzzleRequest = $this->getClient()->createRequest(
|
||||
$request->getMethod(),
|
||||
$request->getUri(),
|
||||
$requestOptions
|
||||
);
|
||||
|
||||
foreach ($this->headers as $name => $value) {
|
||||
$guzzleRequest->setHeader($name, $value);
|
||||
}
|
||||
|
||||
if ('POST' == $request->getMethod() || 'PUT' == $request->getMethod()) {
|
||||
$this->addPostFiles($guzzleRequest, $request->getFiles());
|
||||
}
|
||||
|
||||
// Let BrowserKit handle redirects
|
||||
try {
|
||||
$response = $this->getClient()->send($guzzleRequest);
|
||||
} catch (RequestException $e) {
|
||||
$response = $e->getResponse();
|
||||
if (null === $response) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->createResponse($response);
|
||||
}
|
||||
|
||||
protected function addPostFiles(RequestInterface $request, array $files, $arrayName = '')
|
||||
{
|
||||
foreach ($files as $name => $info) {
|
||||
if (!empty($arrayName)) {
|
||||
$name = $arrayName.'['.$name.']';
|
||||
}
|
||||
|
||||
if (is_array($info)) {
|
||||
if (isset($info['tmp_name'])) {
|
||||
if ('' !== $info['tmp_name']) {
|
||||
$request->getBody()->addFile(new PostFile($name, fopen($info['tmp_name'], 'r'), isset($info['name']) ? $info['name'] : null));
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
$this->addPostFiles($request, $info, $name);
|
||||
}
|
||||
} else {
|
||||
$request->getBody()->addFile(new PostFile($name, fopen($info, 'r')));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function createResponse(GuzzleResponse $response)
|
||||
{
|
||||
$headers = $response->getHeaders();
|
||||
|
||||
return new Response($response->getBody(true), $response->getStatusCode(), $headers);
|
||||
}
|
||||
}
|
14
core/vendor/fabpot/goutte/Goutte/Resources/phar-stub.php
vendored
Normal file
14
core/vendor/fabpot/goutte/Goutte/Resources/phar-stub.php
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Goutte utility.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
require_once 'phar://'.__FILE__.'/vendor/autoload.php';
|
||||
|
||||
__HALT_COMPILER();
|
319
core/vendor/fabpot/goutte/Goutte/Tests/ClientTest.php
vendored
Normal file
319
core/vendor/fabpot/goutte/Goutte/Tests/ClientTest.php
vendored
Normal file
|
@ -0,0 +1,319 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Goutte package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Goutte\Tests;
|
||||
|
||||
use Goutte\Client;
|
||||
use GuzzleHttp\Client as GuzzleClient;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use GuzzleHttp\Message\Response as GuzzleResponse;
|
||||
use GuzzleHttp\Stream\Stream;
|
||||
use GuzzleHttp\Subscriber\History;
|
||||
use GuzzleHttp\Subscriber\Mock;
|
||||
use GuzzleHttp\Post\PostFile;
|
||||
use Symfony\Component\BrowserKit\Cookie;
|
||||
|
||||
/**
|
||||
* Goutte Client Test
|
||||
*
|
||||
* @author Michael Dowling <michael@guzzlephp.org>
|
||||
*/
|
||||
class ClientTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $history;
|
||||
protected $mock;
|
||||
|
||||
protected function getGuzzle()
|
||||
{
|
||||
$this->history = new History();
|
||||
$this->mock = new Mock();
|
||||
$this->mock->addResponse(new GuzzleResponse(200, array(), Stream::factory('<html><body><p>Hi</p></body></html>')));
|
||||
$guzzle = new GuzzleClient(array('redirect.disable' => true, 'base_url' => ''));
|
||||
$guzzle->getEmitter()->attach($this->mock);
|
||||
$guzzle->getEmitter()->attach($this->history);
|
||||
|
||||
return $guzzle;
|
||||
}
|
||||
|
||||
public function testCreatesDefaultClient()
|
||||
{
|
||||
$client = new Client();
|
||||
$this->assertInstanceOf('GuzzleHttp\\ClientInterface', $client->getClient());
|
||||
}
|
||||
|
||||
public function testUsesCustomClient()
|
||||
{
|
||||
$guzzle = new GuzzleClient();
|
||||
$client = new Client();
|
||||
$this->assertSame($client, $client->setClient($guzzle));
|
||||
$this->assertSame($guzzle, $client->getClient());
|
||||
}
|
||||
|
||||
public function testUsesCustomHeaders()
|
||||
{
|
||||
$guzzle = $this->getGuzzle();
|
||||
$client = new Client();
|
||||
$client->setClient($guzzle);
|
||||
$client->setHeader('X-Test', 'test');
|
||||
$crawler = $client->request('GET', 'http://www.example.com/');
|
||||
$this->assertEquals('test', $this->history->getLastRequest()->getHeader('X-Test'));
|
||||
}
|
||||
|
||||
public function testCustomUserAgent()
|
||||
{
|
||||
$guzzle = $this->getGuzzle();
|
||||
$client = new Client();
|
||||
$client->setClient($guzzle);
|
||||
$client->setHeader('User-Agent', 'foo');
|
||||
$crawler = $client->request('GET', 'http://www.example.com/');
|
||||
$this->assertEquals('foo', $this->history->getLastRequest()->getHeader('User-Agent'));
|
||||
}
|
||||
|
||||
public function testUsesAuth()
|
||||
{
|
||||
$guzzle = $this->getGuzzle();
|
||||
$client = new Client();
|
||||
$client->setClient($guzzle);
|
||||
$client->setAuth('me', '**');
|
||||
$crawler = $client->request('GET', 'http://www.example.com/');
|
||||
$request = $this->history->getLastRequest();
|
||||
$this->assertEquals('me', $request->getConfig()->get('auth')[0]);
|
||||
$this->assertEquals('**', $request->getConfig()->get('auth')[1]);
|
||||
$this->assertEquals('basic', $request->getConfig()->get('auth')[2]);
|
||||
}
|
||||
|
||||
public function testResetsAuth()
|
||||
{
|
||||
$guzzle = $this->getGuzzle();
|
||||
$client = new Client();
|
||||
$client->setClient($guzzle);
|
||||
$client->setAuth('me', '**');
|
||||
$client->resetAuth();
|
||||
$crawler = $client->request('GET', 'http://www.example.com/');
|
||||
$request = $this->history->getLastRequest();
|
||||
$this->assertNull($request->getConfig()->get('auth')[0]);
|
||||
$this->assertNull($request->getConfig()->get('auth')[1]);
|
||||
}
|
||||
|
||||
public function testUsesCookies()
|
||||
{
|
||||
$guzzle = $this->getGuzzle();
|
||||
$client = new Client();
|
||||
$client->setClient($guzzle);
|
||||
$client->getCookieJar()->set(new Cookie('test', '123'));
|
||||
$crawler = $client->request('GET', 'http://www.example.com/');
|
||||
$request = $this->history->getLastRequest();
|
||||
$this->assertEquals('test=123', $request->getHeader('Cookie'));
|
||||
}
|
||||
|
||||
public function testUsesPostFiles()
|
||||
{
|
||||
$guzzle = $this->getGuzzle();
|
||||
$client = new Client();
|
||||
$client->setClient($guzzle);
|
||||
$files = array(
|
||||
'test' => array(
|
||||
'name' => 'test.txt',
|
||||
'tmp_name' => __FILE__,
|
||||
),
|
||||
);
|
||||
|
||||
$crawler = $client->request('POST', 'http://www.example.com/', array(), $files);
|
||||
$request = $this->history->getLastRequest();
|
||||
|
||||
$files = $request->getBody()->getFiles();
|
||||
$this->assertFile(reset($files), 'test', 'test.txt', array(
|
||||
'Content-Type' => 'text/plain',
|
||||
'Content-Disposition' => 'form-data; filename="test.txt"; name="test"',
|
||||
));
|
||||
}
|
||||
|
||||
public function testUsesPostNamedFiles()
|
||||
{
|
||||
$guzzle = $this->getGuzzle();
|
||||
$client = new Client();
|
||||
$client->setClient($guzzle);
|
||||
$files = array(
|
||||
'test' => __FILE__,
|
||||
);
|
||||
|
||||
$crawler = $client->request('POST', 'http://www.example.com/', array(), $files);
|
||||
$request = $this->history->getLastRequest();
|
||||
$files = $request->getBody()->getFiles();
|
||||
$this->assertFile(reset($files), 'test', __FILE__, array(
|
||||
'Content-Type' => 'text/x-php',
|
||||
'Content-Disposition' => 'form-data; filename="ClientTest.php"; name="test"',
|
||||
));
|
||||
}
|
||||
|
||||
public function testUsesPostFilesNestedFields()
|
||||
{
|
||||
$guzzle = $this->getGuzzle();
|
||||
$client = new Client();
|
||||
$client->setClient($guzzle);
|
||||
$files = array(
|
||||
'form' => array(
|
||||
'test' => array(
|
||||
'name' => 'test.txt',
|
||||
'tmp_name' => __FILE__,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$crawler = $client->request('POST', 'http://www.example.com/', array(), $files);
|
||||
$request = $this->history->getLastRequest();
|
||||
$files = $request->getBody()->getFiles();
|
||||
$this->assertFile(reset($files), 'form[test]', 'test.txt', array(
|
||||
'Content-Type' => 'text/plain',
|
||||
'Content-Disposition' => 'form-data; filename="test.txt"; name="form[test]"',
|
||||
));
|
||||
}
|
||||
|
||||
public function testUsesPostFilesOnClientSide()
|
||||
{
|
||||
$guzzle = $this->getGuzzle();
|
||||
$client = new Client();
|
||||
$client->setClient($guzzle);
|
||||
$files = array(
|
||||
'test' => __FILE__,
|
||||
);
|
||||
|
||||
$crawler = $client->request('POST', 'http://www.example.com/', array(), $files);
|
||||
$request = $this->history->getLastRequest();
|
||||
$files = $request->getBody()->getFiles();
|
||||
$this->assertFile(reset($files), 'test', __FILE__, array(
|
||||
'Content-Type' => 'text/x-php',
|
||||
'Content-Disposition' => 'form-data; filename="ClientTest.php"; name="test"',
|
||||
));
|
||||
}
|
||||
|
||||
public function testUsesPostFilesUploadError()
|
||||
{
|
||||
$guzzle = $this->getGuzzle();
|
||||
$client = new Client();
|
||||
$client->setClient($guzzle);
|
||||
$files = array(
|
||||
'test' => array(
|
||||
'name' => '',
|
||||
'type' => '',
|
||||
'tmp_name' => '',
|
||||
'error' => 4,
|
||||
'size' => 0,
|
||||
),
|
||||
);
|
||||
|
||||
$crawler = $client->request('POST', 'http://www.example.com/', array(), $files);
|
||||
$request = $this->history->getLastRequest();
|
||||
|
||||
$this->assertEquals(array(), $request->getBody()->getFiles());
|
||||
}
|
||||
|
||||
public function testCreatesResponse()
|
||||
{
|
||||
$guzzle = $this->getGuzzle();
|
||||
$client = new Client();
|
||||
$client->setClient($guzzle);
|
||||
$crawler = $client->request('GET', 'http://www.example.com/');
|
||||
$this->assertEquals('Hi', $crawler->filter('p')->text());
|
||||
}
|
||||
|
||||
public function testHandlesRedirectsCorrectly()
|
||||
{
|
||||
$guzzle = $this->getGuzzle();
|
||||
|
||||
$this->mock->clearQueue();
|
||||
$this->mock->addResponse(new GuzzleResponse(301, array(
|
||||
'Location' => 'http://www.example.com/',
|
||||
)));
|
||||
$this->mock->addResponse(new GuzzleResponse(200, [], Stream::factory('<html><body><p>Test</p></body></html>')));
|
||||
|
||||
$client = new Client();
|
||||
$client->setClient($guzzle);
|
||||
|
||||
$crawler = $client->request('GET', 'http://www.example.com/');
|
||||
$this->assertEquals('Test', $crawler->filter('p')->text());
|
||||
|
||||
// Ensure that two requests were sent
|
||||
$this->assertEquals(2, count($this->history));
|
||||
}
|
||||
|
||||
public function testConvertsGuzzleHeadersToArrays()
|
||||
{
|
||||
$guzzle = $this->getGuzzle();
|
||||
|
||||
$this->mock->clearQueue();
|
||||
$this->mock->addResponse(new GuzzleResponse(200, array(
|
||||
'Date' => 'Tue, 04 Jun 2013 13:22:41 GMT',
|
||||
)));
|
||||
|
||||
$client = new Client();
|
||||
$client->setClient($guzzle);
|
||||
$client->request('GET', 'http://www.example.com/');
|
||||
$response = $client->getResponse();
|
||||
$headers = $response->getHeaders();
|
||||
|
||||
$this->assertInternalType("array", array_shift($headers), "Header not converted from Guzzle\Http\Message\Header to array");
|
||||
}
|
||||
|
||||
public function testNullResponseException()
|
||||
{
|
||||
$this->setExpectedException('GuzzleHttp\Exception\RequestException');
|
||||
$guzzle = $this->getGuzzle();
|
||||
$this->mock->clearQueue();
|
||||
$exception = new RequestException('', $this->getMock('GuzzleHttp\Message\RequestInterface'));
|
||||
$this->mock->addException($exception);
|
||||
$client = new Client();
|
||||
$client->setClient($guzzle);
|
||||
$client->request('GET', 'http://www.example.com/');
|
||||
$response = $client->getResponse();
|
||||
}
|
||||
|
||||
protected function assertFile(PostFile $postFile, $fieldName, $fileName, $headers)
|
||||
{
|
||||
$this->assertEquals($postFile->getName(), $fieldName);
|
||||
$this->assertEquals($postFile->getFilename(), $fileName);
|
||||
|
||||
$postFileHeaders = $postFile->getHeaders();
|
||||
|
||||
// Note: Sort 'Content-Disposition' values before comparing, because the order changed in Guzzle 4.2.2
|
||||
$postFileHeaders['Content-Disposition'] = explode('; ', $postFileHeaders['Content-Disposition']);
|
||||
sort($postFileHeaders['Content-Disposition']);
|
||||
$headers['Content-Disposition'] = explode('; ', $headers['Content-Disposition']);
|
||||
sort($headers['Content-Disposition']);
|
||||
|
||||
$this->assertEquals($postFileHeaders, $headers);
|
||||
}
|
||||
|
||||
public function testHttps()
|
||||
{
|
||||
$guzzle = $this->getGuzzle();
|
||||
|
||||
$this->mock->clearQueue();
|
||||
$this->mock->addResponse(new GuzzleResponse(200, [], Stream::factory('<html><body><p>Test</p></body></html>')));
|
||||
$client = new Client();
|
||||
$client->setClient($guzzle);
|
||||
$crawler = $client->request('GET', 'https://www.example.com/');
|
||||
$this->assertEquals('https', $this->history->getLastRequest()->getScheme());
|
||||
$this->assertEquals('Test', $crawler->filter('p')->text());
|
||||
}
|
||||
|
||||
public function testCustomUserAgentConstructor()
|
||||
{
|
||||
$guzzle = $this->getGuzzle();
|
||||
$client = new Client([
|
||||
'HTTP_HOST' => '1.2.3.4',
|
||||
'HTTP_USER_AGENT' => 'SomeHost',
|
||||
]);
|
||||
$client->setClient($guzzle);
|
||||
$crawler = $client->request('GET', 'http://www.example.com/');
|
||||
$this->assertEquals('SomeHost', $this->history->getLastRequest()->getHeader('User-Agent'));
|
||||
}
|
||||
}
|
19
core/vendor/fabpot/goutte/LICENSE
vendored
Normal file
19
core/vendor/fabpot/goutte/LICENSE
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
Copyright (c) 2010-2013 Fabien Potencier
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
114
core/vendor/fabpot/goutte/README.rst
vendored
Normal file
114
core/vendor/fabpot/goutte/README.rst
vendored
Normal file
|
@ -0,0 +1,114 @@
|
|||
Goutte, a simple PHP Web Scraper
|
||||
================================
|
||||
|
||||
Goutte is a screen scraping and web crawling library for PHP.
|
||||
|
||||
Goutte provides a nice API to crawl websites and extract data from the HTML/XML
|
||||
responses.
|
||||
|
||||
Requirements
|
||||
------------
|
||||
|
||||
Goutte depends on PHP 5.4+ and Guzzle 4+.
|
||||
|
||||
.. tip::
|
||||
|
||||
If you need support for PHP 5.3 or Guzzle 3, use Goutte 1.0.6.
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
Add ``fabpot/goutte`` as a require dependency in your ``composer.json`` file:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
php composer.phar require fabpot/goutte:~2.0
|
||||
|
||||
.. tip::
|
||||
|
||||
You can also download the `Goutte.phar`_ file:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
require_once '/path/to/goutte.phar';
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
Create a Goutte Client instance (which extends
|
||||
``Symfony\Component\BrowserKit\Client``):
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
use Goutte\Client;
|
||||
|
||||
$client = new Client();
|
||||
|
||||
Make requests with the ``request()`` method:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
// Go to the symfony.com website
|
||||
$crawler = $client->request('GET', 'http://www.symfony.com/blog/');
|
||||
|
||||
The method returns a ``Crawler`` object
|
||||
(``Symfony\Component\DomCrawler\Crawler``).
|
||||
|
||||
Fine-tune cURL options:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
$client->getClient()->setDefaultOption('config/curl/'.CURLOPT_TIMEOUT, 60);
|
||||
|
||||
Click on links:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
// Click on the "Security Advisories" link
|
||||
$link = $crawler->selectLink('Security Advisories')->link();
|
||||
$crawler = $client->click($link);
|
||||
|
||||
Extract data:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
// Get the latest post in this category and display the titles
|
||||
$crawler->filter('h2.post > a')->each(function ($node) {
|
||||
print $node->text()."\n";
|
||||
});
|
||||
|
||||
Submit forms:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
$crawler = $client->request('GET', 'http://github.com/');
|
||||
$crawler = $client->click($crawler->selectLink('Sign in')->link());
|
||||
$form = $crawler->selectButton('Sign in')->form();
|
||||
$crawler = $client->submit($form, array('login' => 'fabpot', 'password' => 'xxxxxx'));
|
||||
$crawler->filter('.flash-error')->each(function ($node) {
|
||||
print $node->text()."\n";
|
||||
});
|
||||
|
||||
More Information
|
||||
----------------
|
||||
|
||||
Read the documentation of the BrowserKit and DomCrawler Symfony Components for
|
||||
more information about what you can do with Goutte.
|
||||
|
||||
Technical Information
|
||||
---------------------
|
||||
|
||||
Goutte is a thin wrapper around the following fine PHP libraries:
|
||||
|
||||
* Symfony Components: BrowserKit, CssSelector and DomCrawler;
|
||||
|
||||
* `Guzzle`_ HTTP Component.
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
Goutte is licensed under the MIT license.
|
||||
|
||||
.. _`Composer`: http://getcomposer.org
|
||||
.. _`Goutte.phar`: http://get.sensiolabs.org/goutte.phar
|
||||
.. _`Guzzle`: http://docs.guzzlephp.org
|
21
core/vendor/fabpot/goutte/box.json
vendored
Normal file
21
core/vendor/fabpot/goutte/box.json
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"output": "goutte.phar",
|
||||
"chmod": "0755",
|
||||
"compactors": [
|
||||
"Herrera\\Box\\Compactor\\Php"
|
||||
],
|
||||
"extract": false,
|
||||
"files": [
|
||||
"LICENSE",
|
||||
"Goutte/Client.php"
|
||||
],
|
||||
"finder": [
|
||||
{
|
||||
"name": ["*.php", "*.pem*"],
|
||||
"exclude": ["Tests", "tests"],
|
||||
"in": "vendor"
|
||||
}
|
||||
],
|
||||
"stub": "Goutte/Resources/phar-stub.php",
|
||||
"web": false
|
||||
}
|
29
core/vendor/fabpot/goutte/composer.json
vendored
Normal file
29
core/vendor/fabpot/goutte/composer.json
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"name": "fabpot/goutte",
|
||||
"type": "application",
|
||||
"description": "A simple PHP Web Scraper",
|
||||
"keywords": ["scraper"],
|
||||
"homepage": "https://github.com/FriendsOfPHP/Goutte",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Fabien Potencier",
|
||||
"email": "fabien@symfony.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.4.0",
|
||||
"symfony/browser-kit": "~2.1",
|
||||
"symfony/css-selector": "~2.1",
|
||||
"symfony/dom-crawler": "~2.1",
|
||||
"guzzlehttp/guzzle": ">=4,<6"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Goutte\\": "Goutte" }
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.0-dev"
|
||||
}
|
||||
}
|
||||
}
|
18
core/vendor/fabpot/goutte/phpunit.xml.dist
vendored
Normal file
18
core/vendor/fabpot/goutte/phpunit.xml.dist
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false"
|
||||
bootstrap="./vendor/autoload.php">
|
||||
<testsuites>
|
||||
<testsuite name="Goutte Test Suite">
|
||||
<directory>./Goutte/Tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
Reference in a new issue