刮擦有问题
我正在尝试从文本文件的列表中、从域中抓取一些页面并将它们保存到我的服务器上。
我有以下代码(域被隐藏),从文件目录的文本文件列表中进行筛选,然后复制文件名,但附加 .html。
由于某种原因,它创建文件而没有实际成功写入它们。我做错了什么?
<?php
$file = fopen("list.txt","r");
while(! feof($file))
{
$line = fgets($file);
$url = "http://www.????.com". $line;
$homepage = @file_get_contents($url);
$newname = rtrim(substr(strrchr($line, "/"), 1)) . ".html";
$fh = fopen($newname, 'w') or die("can't open file");
$stringData = $homepage;
fwrite($fh, $stringData);
fclose($fh);
}
fclose($file);
echo "success!";
?>
I'm trying to scrape some pages, from a list on a text file, from a domain and save them onto my server.
I have the following code (with the domain obscured), culling from a text file list of the file directories, and then copying the file names, but with .html appended.
For some reason, its creating the files without actually successfully writing to them. What am I doing wrong?
<?php
$file = fopen("list.txt","r");
while(! feof($file))
{
$line = fgets($file);
$url = "http://www.????.com". $line;
$homepage = @file_get_contents($url);
$newname = rtrim(substr(strrchr($line, "/"), 1)) . ".html";
$fh = fopen($newname, 'w') or die("can't open file");
$stringData = $homepage;
fwrite($fh, $stringData);
fclose($fh);
}
fclose($file);
echo "success!";
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该删除 file_get_contents 之前的@。如果它给你一个错误,@将阻止它显示。
也许您没有安装 fopen 包装器,或者 url 返回 404。除非您看到该调用的警告或错误,否则您无法判断。
You should remove the @ before file_get_contents. If it is giving you an error, the @ will prevent it from displaying.
Maybe you don't have fopen wrappers installed, or the url returned 404. You can't tell unless you see the warning or error from that call.