drzk21632 2017-04-22 17:00
浏览 74
已采纳

PHP简单HTML DOM解析器在有效URL上返回false

I'm trying the following:

$url = 'https://www.tripadvisor.es/Hotels-g187514-Madrid-Hotels.html'

$ta_html = file_get_html($url);
var_dump($ta_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'

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?

This seems to be a duplicate of this problem: Simple HTML DOM returning false that is also unanswered

  • 写回答

4条回答 默认 最新

  • douzhang8033 2018-09-03 14:33
    关注

    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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败