访问网站 - WWW::Mechanize

发布于 2024-12-15 12:07:25 字数 652 浏览 0 评论 0原文

我尝试使用下面的代码来获取网站 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苄①跕圉湢 2024-12-22 12:07:25

这是一种奇怪的行为,但是您想要检索的网址上的站点需要定义以下标头:定义
接受、接受编码、接受语言、接受字符集、Cookie。

否则服务器根本不响应。

您可以轻松地做到这一点,只需在“获取”请求之前插入以下代码:

$browser->add_header(
    "Accept"          => "",
    "Accept-Encoding" => "",
    "Accept-Language" => "",
    "Accept-Charset"  => "",
    "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:

$browser->add_header(
    "Accept"          => "",
    "Accept-Encoding" => "",
    "Accept-Language" => "",
    "Accept-Charset"  => "",
    "Cookie"          => ""
);

Instead of empty fields you can insert some real values, but this works too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文