访问网站 - WWW::Mechanize
我尝试使用下面的代码来获取网站 htm 源代码并且它有效。但是,当我访问网站 http://reserve.apple.com/WebObjects/ 时,我无法得到结果ProductReservation.woa/wa/reserveProduct 使用如下代码。但是,我可以正确使用浏览器访问该页面。您能给我一些解决这个问题的提示或技巧吗?谢谢。
#!/usr/bin/perl
use strict;
use warnings;
# create a new browser
use WWW::Mechanize;
my $browser = WWW::Mechanize->new();
# tell it to get the main page
my $sURL = 'http://www.apple.com';
#my $sURL = 'http://reserve.apple.com/WebObjects/ProductReservation.woa/wa/reserveProduct';
$browser->get($sURL);
print $browser->content;
exit(0);
I try to use the code as below to get the website htm source and it works. However, I cannot get the result when I visit the website http://reserve.apple.com/WebObjects/ProductReservation.woa/wa/reserveProduct by using code as below. But, I can access this page by using browser properly. Would you give me some hints or tips to fix this problem? Thank you.
#!/usr/bin/perl
use strict;
use warnings;
# create a new browser
use WWW::Mechanize;
my $browser = WWW::Mechanize->new();
# tell it to get the main page
my $sURL = 'http://www.apple.com';
#my $sURL = 'http://reserve.apple.com/WebObjects/ProductReservation.woa/wa/reserveProduct';
$browser->get($sURL);
print $browser->content;
exit(0);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一种奇怪的行为,但是您想要检索的网址上的站点需要定义以下标头:定义:
接受、接受编码、接受语言、接受字符集、Cookie。
否则服务器根本不响应。
您可以轻松地做到这一点,只需在“获取”请求之前插入以下代码:
您可以插入一些实际值,而不是空字段,但这也有效。
It's a strange behavior, but site at url you want to retrieve requires following headers to be defined:
Accept, Accept-Encoding, Accept-Language, Accept-Charset, Cookie.
Otherwise server does not respond at all.
You can easy do this just inserting following code before your "get" request:
Instead of empty fields you can insert some real values, but this works too.