Skip to content

Instantly share code, notes, and snippets.

@sasezaki
Created May 29, 2012 14:29
Show Gist options
  • Select an option

  • Save sasezaki/2828746 to your computer and use it in GitHub Desktop.

Select an option

Save sasezaki/2828746 to your computer and use it in GitHub Desktop.
Goutte Wrapper by Diggin_Http_Charset for CP932
<?php
use Goutte\Client;
use Guzzle\Http\Message\Response as GuzzleResponse;
use Symfony\Component\BrowserKit\Response;
use Diggin\Http\Charset\WrapperFactory;
class GoutteWrapper extends Client
{
protected function createResponse(GuzzleResponse $response)
{
$response = new Response($response->getBody(true), $response->getStatusCode(), $response->getHeaders()->getAll());
return WrapperFactory::factory($response);
}
}
$url = 'http://www.kms.gol.com/benkyo/ben1.htm';
if (isset($argv[1])) {
$client = new GoutteWrapper;
} else {
$client = new Client;
}
$crawler = $client->request('GET', $url);
$title = $crawler->filterXpath('//title')->text();
echo $title; // ①文書情報マネジメントとは?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment