dtry54612 2015-03-22 17:28
浏览 57
已采纳

PHP simple_html_dom无法正确解析Apple维基百科页面

I am trying to parse a Wikipedia page - and for some reason below code works for all Wikipedia pages (except the Apple Wikipedia page!!!)

include ('simple_html_dom.php');
$url = "http://en.wikipedia.org/wiki/Apple_Inc.";

$html = file_get_html($url);

Strlen for $html above returns 0 above for Apple.

Note: the above code works perfectly fine when $url is set to other Wikipedia pages for Microsoft - http://en.wikipedia.org/wiki/Microsoft - for Diageo - http://en.wikipedia.org/wiki/Diageo, etc

I want to use file_get_html - so that i can get it into a DOM object and process it further.

  • 写回答

1条回答 默认 最新

  • dongxuying7583 2015-03-22 17:47
    关注

    Change MAX_FILE_SIZE constant in simple_html_dom.php to, e.g.

    define('MAX_FILE_SIZE', 800000);
    

    and you are good to go... :) This is way you got '0' in case of apple page. Strlen is above limit...

    if (empty($contents) || strlen($contents) > MAX_FILE_SIZE)
    {
        return false;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了