如何为 LWP::RobotUA 指定自己的 robots.txt 规则

发布于 2024-12-22 14:17:47 字数 358 浏览 5 评论 0原文

我编写了一个脚本来使用 LWP::RobotUA 检查我自己的网站。我想避免频繁请求我的 robots.txt。

LWP::RobotUA 的规则参数应该允许我指定这些,但我不太明白“允许所有页面”应该传递什么。

my $ua = LWP::RobotUA->new(agent=>'my-robot/0.1', from=>'[email protected]', rules=> ??? );

I wrote a script to check my own websites with LWP::RobotUA. I would like to avoid the frequent requests for my robots.txt.

The rules parameter for LWP::RobotUA should allow me to specify those, but I don't qiute understand what should be passed for "allow all pages".

my $ua = LWP::RobotUA->new(agent=>'my-robot/0.1', from=>'[email protected]', rules=> ??? );

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

黯然#的苍凉 2024-12-29 14:17:47

LWP::RobotUA 是添加了 robots.txt 支持的 LWP::UserAgent。如果您不想请求robots.txt,那么只需使用LWP::UserAgent。

或者,子类化 LWP::RobotUA 并重写 simple_request 方法并删除 robots.txt 和规则处理。

LWP::RobotUA is LWP::UserAgent with robots.txt support added. If you do not want to request robots.txt, then just use LWP::UserAgent.

Alternatively, subclass LWP::RobotUA and override the simple_request method and strip out robots.txt and rule handling.

小鸟爱天空丶 2024-12-29 14:17:47

经过更多研究,我认为提供机器人规则的预期方法是对 WWW::RobotRules 进行子类化。

{
    package WWW::NoRules;
    use vars qw(@ISA);
    use WWW::RobotRules;
    @ISA = qw(WWW::RobotRules::InCore);

    sub allowed {
        return 1;
    }
}

my $ua = LWP::RobotUA->new(agent=>'my-robot/0.1', from=>'[email protected]', rules=>WWW::NoRules->new);

After more research, I think the intended way to supply robots rules is by subclassing WWW::RobotRules.

{
    package WWW::NoRules;
    use vars qw(@ISA);
    use WWW::RobotRules;
    @ISA = qw(WWW::RobotRules::InCore);

    sub allowed {
        return 1;
    }
}

my $ua = LWP::RobotUA->new(agent=>'my-robot/0.1', from=>'[email protected]', rules=>WWW::NoRules->new);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文