php - str_get_html 不起作用并返回空白

标签 php

运行下面的代码后出现黑屏

<?php include('simple_html_dom.php');
$html = getSslPage('https://www.reddit.com/r/nottheonion/comments/3aev89/kim_jongun_claims_to_have_cured_aids_ebola_and/');


function getSslPage($url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_REFERER, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}

$html = str_get_html($html);

echo $html;

调试它最困难的部分是它有时会与其他 url 一起工作。我想知道为什么页面具有相同的 DOM 结构。任何人都知道为什么会这样?

最佳答案

是因为html字符串太大,simple_html_dom有最大解析限制。以下是您可以提高限制的方法。

打开 simple_html_dom.php 并更改这一行

define('MAX_FILE_SIZE', 6000000);

更多..尝试

define('MAX_FILE_SIZE', 60000000); // add a zero at the end

这应该可以解决问题。如果不是这样,请告诉我。

关于php - str_get_html 不起作用并返回空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30966569/

相关文章:

PHP:减小 'save as' 窗口的大小

PHP暴力密码生成器

php - 从现在起 x 天后从数据库中选择过去的日期

php - Laravel - 一般错误 : 1366 Incorrect integer value

php - 使用 PHP SELECT 然后将数据插入 MySQL

php - php mysql 中带引号和不带引号的搜索

javascript - 处理嵌套文件包含在 php 中并将值返回给 javascript 函数

php - 如何使用 jquery 和 ajax 查询 mysql 数据库?

php - 使用 php 变量来操作 html 的标题和正文的 Id (有人这样做吗?)

php - 初学者 php mysql - 从输入表单将数据插入到表中