我正在使用
Goutte在UTF-8网站上搜索,内部使用Guzzle.该网站声明了UTF-8的元标记,因此:
但是,内容类型标题是:
Content-Type: text/html
并不是:
Content-Type: text/html; charset=utf-8
因此,当我刮,Goutte没有发现它是UTF-8,并且错误地抓取数据.远程站点不在我的控制之下,所以我无法解决问题!这是一组用于复制问题的脚本.一,刮刀:
require_once realpath(__DIR__ . '/..') . '/vendor/goutte/goutte.phar';
$url = 'http://crawler-tests.local/utf-8.php';
use Goutte\Client;
$client = new Client();
$crawler = $client->request('get', $url);
$text = $crawler->text();
echo 'Whole page: ' . $text . "\n";
现在是一个放在Web服务器上的测试页面:
// Correct
#header('Content-Type: text/html; charset=utf-8');
// Incorrect
header('Content-Type: text/html');
?>
UTF-8 testWhen the Content-Header header is incomplete, the pound sign breaks:
£15,216
这是Goutte测试的输出:
Whole page: UTF-8 test
When the Content-Header header is incomplete, the pound sign breaks: £15,216
正如您在上一个脚本中的注释中所看到的,正确地声明标头中的字符集可以修复问题.我在Goutte周围寻找,看看是否有任何东西看起来会迫使字符集,但无济于事.有任何想法吗?