Why can't I fetch wikipedia pages with LWP::Simple?

前端 未结 5 828
我在风中等你
我在风中等你 2021-01-11 16:52

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(\"ht         


        
5条回答
  •  自闭症患者
    2021-01-11 17:30

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

    The following works instead:

    #!/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;
    

提交回复
热议问题