PHP简单HTML DOM解析器在有效url上返回false [英] PHP Simple HTML DOM Parser returning false on valid url
问题描述
我正在尝试以下操作:
$url = 'https://www.tripadvisor.es/Hotels-g187514-Madrid-Hotels.html'
$ta_html = file_get_html($url);
var_dump($ta_html);
它返回false,这可以正常工作并正确获取html的
it returns false, this is working and correctly getting the html for:
$url = 'https://www.tripadvisor.es/Hotels-g294316-Lima_Lima_Region-Hotels.html#ACCOM_OVERVIEW'
我首先想到的是它具有重定向功能,但是我用curl及其200 ok检查了页眉,在两种情况下看起来都一样.会发生什么事?该如何解决?
My first thought was that it had a redirect but I checked the headers with curl and its 200 ok and it seemed like the same on both cases. What can be happening? how it can be solved?
这似乎是此问题的重复: 返回错误的简单HTML DOM ,也未得到答复
This seems to be a duplicate of this problem: Simple HTML DOM returning false that is also unanswered
推荐答案
似乎HTML DOM解析器失败,因为HTML文件大小大于库的最大文件大小.当您调用file_get_html()
时,它会根据其MAX_FILE_SIZE
常量进行文件大小检查.因此,在调用任何HTML DOM解析器方法之前,请通过调用以下命令增加库使用的最大文件大小:
It looks like HTML DOM parser is failing because the HTML file size is greater than the library's max file size. When you call file_get_html()
it does a file size check based on it's MAX_FILE_SIZE
constant. So before calling any HTML DOM parser methods, increase the max file size used by the library by calling:
define('MAX_FILE_SIZE', 1200000); // or larger if needed, default is 600000
您也发现,您可以执行此操作来解决文件大小检查问题
Also as as you found out you can work around the file size check with doing this
$html = new simple_html_dom();
$html->load($str);
这篇关于PHP简单HTML DOM解析器在有效url上返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!