“get” not working in perl

て烟熏妆下的殇ゞ 提交于 2019-12-02 17:26:41

问题


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";

回答1:


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

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

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).

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



来源:https://stackoverflow.com/questions/6296653/get-not-working-in-perl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!