“得到"不能在 perl 中工作 [英] "get" not working in perl

查看:27
本文介绍了“得到"不能在 perl 中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 perl 的新手.在过去的几天里,我制作了一些简单的脚本,通过get"将网站的源代码保存到我的电脑中.他们做他们应该做的事情,但不会获得论坛网站的内容.非论坛网站工作得很好.知道发生了什么吗?这是问题块:

I'm new to perl. In the past few days, I've made some simple scripts that save websites' source codes to my computer via "get." They do what they're supposed to, but will not get the content of a website which is a forum. Non-forum websites work just fine. Any idea what's going on? Here's the problem chunk:

my $url = 'http://www.computerforum.com/';
my $content = get $url || die "Unable to get content";

推荐答案

http://p3rl.org/LWP::Simple#get:

get() 函数将获取由给定 URL 标识的文档并返回它.如果失败,它将返回 undef.[…]

The get() function will fetch the document identified by the given URL and return it. It returns undef if it fails. […]

当您使用此功能访问网络时,您将无法检查响应代码或响应标头(如Content-Type").如果您需要该信息,您应该使用完整的 OO 界面(请参阅 LWP::UserAgent).

You will not be able to examine the response code or response headers (like 'Content-Type') when you are accessing the web using this function. If you need that information you should use the full OO interface (see LWP::UserAgent).

您确实需要更好的错误报告,请切换到 LWP::UserAgent 库.我怀疑论坛软件阻止了 LWP 用户代理.

You really need better error reporting, switch to the LWP::UserAgent library. I suspect the forum software blocks the LWP user agent.

这篇关于“得到"不能在 perl 中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆