【发布时间】:2018-12-13 05:11:19
【问题描述】:
我正在使用 Laravel 5.1 在 /public/download 文件夹中,我需要获取许多 .htm 页面,所以我写了:
public function scraper() {
$path = 'downloads/';
$files = scandir($path);
foreach ($files as $k => $file) {
if ($k < 2) continue;
$html = file_get_contents($file);
//parse the html into a DOMDocument
$dom = new DOMDocument();
@$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate("//div[@class='merchant-links']/a/@href");
echo $hrefs;
}
}
但我得到了错误:
AdminController.php 第 133 行中的 ErrorException: file_get_contents(1742-wine-bar-1.htm):打开流失败:没有这样的文件或目录 我也试试:
$path = 'C:/wamp/www/mavis/public/downloads/';
【问题讨论】:
标签: php laravel file-get-contents scandir