为什么我不能使用 LWP::Simple 获取维基百科页面? [英] Why can't I fetch wikipedia pages with LWP::Simple?

查看:72
本文介绍了为什么我不能使用 LWP::Simple 获取维基百科页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 LWP::Simple 获取维基百科页面,但它们不回来了.这段代码:

I'm trying to fetch Wikipedia pages using LWP::Simple, but they're not coming back. This code:

#!/usr/bin/perl
use strict;
use LWP::Simple;

print get("http://en.wikipedia.org/wiki/Stack_overflow");

不打印任何东西.但如果我使用其他网页,请说 http://www.google.com,它工作正常.

doesn't print anything. But if I use some other webpage, say http://www.google.com, it works fine.

我应该使用其他名称来引用维基百科页面吗?

Is there some other name that I should be using to refer to Wikipedia pages?

这里会发生什么?

推荐答案

显然维基百科阻止了 LWP::Simple 请求:http://www.perlmonks.org/?node_id=695886

Apparently Wikipedia blocks LWP::Simple requests: http://www.perlmonks.org/?node_id=695886

以下工作代替:

#!/usr/bin/perl
use strict;
use LWP::UserAgent;

my $url = "http://en.wikipedia.org/wiki/Stack_overflow";

my $ua = LWP::UserAgent->new();
my $res = $ua->get($url);

print $res->content;

这篇关于为什么我不能使用 LWP::Simple 获取维基百科页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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