Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 简单的html dom不适用于某些网站_Php_Dom_Simple Html Dom - Fatal编程技术网

Php 简单的html dom不适用于某些网站

Php 简单的html dom不适用于某些网站,php,dom,simple-html-dom,Php,Dom,Simple Html Dom,simple_html_dom不适用于某些网站并返回未知代码: $html = file_get_html('http://www.tsetmc.com/loader.aspx?ParTree=151311&i=49776615757150035'); echo $html; 结果如下: �D�}R��][��ƕ~OU�̇p�����" gK�e[�8+[���)� B3t8䘄F�8�Z[7�ʿ�/rT�'����K~i��/�s��0��h��>���ڷ�7�����8����

simple_html_dom不适用于某些网站并返回未知代码:

$html = file_get_html('http://www.tsetmc.com/loader.aspx?ParTree=151311&i=49776615757150035');
echo $html;
结果如下:

�D�}R��][��ƕ~OU�̇p�����" gK�e[�8+[���)� B3t8䘄F�8�Z[7�ʿ�/rT�'����K~i��/�s��0��h��>���ڷ�7�����8��������(l��Eq������;��V������u�tƝ[ݨ���{qԋ[�kW[Q� j��ĝ���n\�{�ʅ��p�=�����#���??�����I�����s�޾�ۏ;������?<���$xݓV��vo��AxQ|-��6'7oƧ��R|�s�ۀ��ޝn��ӟ�����ǭ^t����߼��|O4�76/�?��Qo���ս��5�at¶�p���� ����-n5�9o6u����Ŀv�Q�v

如何解决此问题?

这里的根本问题至少在我的计算机上,可能与您的版本不同。。。该站点返回gzip数据,并且在传递给dom解析器之前,php和curl没有对其进行适当的解压缩。如果您使用的是PHP5.4,那么您可以使用gzdecode和file_get_内容自行解压

在较旧的php版本上,此代码可以工作:

<?php
    // download the site
    $data = file_get_contents("http://www.tsetmc.com/loader.aspx?ParTree=151311&i=49776615757150035");
    // decompress it (a bit hacky to strip off the gzip header)
    $data = gzinflate(substr($data, 10, -8));
    include("simple_html_dom.php");
    // parse and use
    $html = str_get_html($data);
    echo $html->root->innertext();

你检查了吗:我刚刚编辑了我的答案,我想我在这里发现了真正的问题…使用与你的问题相同的url还是不同的url?在问题中使用相同的url我发现了根本问题:实际上是文件内容没有压缩数据。因此,它试图将压缩数据解析为html,而这就是垃圾。PHP5.4有一个内置的gzip解码功能,但不是以前的版本…thanx很多。还有一个问题。。。此代码不显示此url的源,而是显示主页url。。下面你可以看到源代码得到。。。但它不是目标页面源。。。我们调用以获取:的源代码,并接收一些类似的代码:问题是什么:?例如,类box1 red tbl zi1_4 h110不在php的get源代码中。。。但它存在于原始页面中:
header('Content-Type: text/html; charset=utf-8');