PHP 文件名不能为空如何在简单的 html dom 第 70 行中绕过它

问题描述 投票:0回答:2

当我抓取一个网站时,我能够将其抓取到 10000 个内容中的 4000 个,它会停下来并说

PHP 警告:file_get_contents():文件名不能为空 /Users...simple_html_dom.php 第 70 行 PHP 致命错误:调用 非对象上的成员函数 find()

在 simple_html_dom.php 的第 70 行

$contents = file_get_contents($url, $use_include_path, $context, $offset);

我想知道如何绕过空文件名并继续完成该过程?

php web-scraping
2个回答
2
投票
$contents = '';
if(!empty($url)) {
    $contents = file_get_contents($url, $use_include_path, $context, $offset);
}

1
投票

您可能只需要确保 $url 有一个值...

if(!empty($url)) {
    $contents = file_get_contents($url, $use_include_path, $context, $offset);
}
© www.soinside.com 2019 - 2024. All rights reserved.