刮擦有问题

发布于 2024-08-06 20:02:41 字数 555 浏览 2 评论 0原文

我正在尝试从文本文件的列表中、从域中抓取一些页面并将它们保存到我的服务器上。

我有以下代码(域被隐藏),从文件目录的文本文件列表中进行筛选,然后复制文件名,但附加 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

玩物 2024-08-13 20:02:41

您应该删除 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文