无法使用 Perl 的 LWP 代理检索网页内容
我有一个程序可以检索特定网页的内容,但在某些页面上出现错误:
Can't get http://www.sitename.com
302 Moved Temporarily at geturl.pl line 30.
该网站在浏览器上显示正常。
想知道我可以做什么来获取内容?
我的代码非常简单,标准使用 LWP 并且在大多数页面上运行良好。
my $browser = LWP::UserAgent->new(
agent=>'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)',
keep_alive=>'1'
);
...
my $response = $browser->get($url);
谢谢!
================
更新:
- 是的,这是我正在使用的实际代码。是否有明确的选项可以打开以下功能 重定向?
- 是的,wget 可以工作,
谢谢
I have a program that can retrieve the content of a specific webpage, but there are some pages where I get an error:
Can't get http://www.sitename.com
302 Moved Temporarily at geturl.pl line 30.
The site displays fine on a browser.
Wonder what I could do to get the content?
My code is very simple, the standard use of LWP and works fine on most pages.
my $browser = LWP::UserAgent->new(
agent=>'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)',
keep_alive=>'1'
);
...
my $response = $browser->get($url);
Thanks!
================
update:
- Yes this is the actual code I'm using. Is there an explicit option to turn on following
redirects? - Yes wget works
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
LWP::UserAgent 文档表明
请求
用户代理上的方法将自动遵循重定向。从本文档中不清楚get
是否使用相同的逻辑。您可以通过创建 HTTP::Request 对象来使用请求方法。此示例使用
request
方法:The LWP::UserAgent docs indicate that the
request
method on the user agent will follow redirects automatically. It's unclear from this documentation ifget
uses the same logic.You could use the request method by creating an HTTP::Request object. This example uses the
request
method:我刚刚阅读了 有关一些可以执行的各种模块的演讲的幻灯片Perl 中的 HTTP;也许你可以尝试其他之一,例如 HTTP::Tiny:
I just read slides from a talk about some of various modules that can do HTTP in Perl; maybe you could try one of the others, like HTTP::Tiny: