使用 LWP::UserAgent 的 Perl 代码在做什么?

发布于 2024-09-01 14:27:18 字数 447 浏览 4 评论 0原文

我有这段代码:

use strict;
use LWP::UserAgent;
use warnings;
my $ua = new LWP::UserAgent(agent => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.5) Gecko/20060719 Firefox/1.5.0.5');
$ua->proxy([qw(http https)] => 'http://59.39.92.148:1080');
my $response = $ua->get("http://www.google.com");
print $response->code,' ', $response->message,"\n";

代码的含义是“使用sock代理打开www.google.com”吗?解释是什么?

I have this code:

use strict;
use LWP::UserAgent;
use warnings;
my $ua = new LWP::UserAgent(agent => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.5) Gecko/20060719 Firefox/1.5.0.5');
$ua->proxy([qw(http https)] => 'http://59.39.92.148:1080');
my $response = $ua->get("http://www.google.com");
print $response->code,' ', $response->message,"\n";

Is the meaning of the code "open www.google.com with sock proxy"? What is the explanation?

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

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

发布评论

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

评论(3

dawn曙光 2024-09-08 14:27:18

它正在实例化一个 LWP::UserAgent 对象。

最后:

print $response->code,' ', $response->message,"\n";`

允许向用户做出响应

我是一名 C# 开发人员,但这就是我的看法:)

It's instantiating an LWP::UserAgent object.

Finally:

print $response->code,' ', $response->message,"\n";`

allows a response to be posed back to the user

I'm a C# developer, but that's how it looks to me :)

庆幸我还是我 2024-09-08 14:27:18

该代码正在设置一个 LWP::UserAgent 对象来伪装成使用的浏览器由人类绕过谷歌的蜘蛛检测机制。这样做违反了 Google 服务条款

5.3 您同意不通过 Google 提供的界面以外的任何方式访问(或尝试访问)任何服务,除非您在与 Google 签订的单独协议中获得明确允许。您明确同意不通过任何自动方式(包括使用脚本或网络爬虫)访问(或尝试访问)任何服务,并应确保您遵守服务上存在的任何 robots.txt 文件中规定的说明.

59.39.92.148 可能是中国一些受损(或配置错误)的开放代理。设置 $ua 来使用它是试图隐藏 TOS 违规的根源。

顺便说一句,您应该知道,如果您决定走这条路线,59.39.92.148 的服务器将能够记录和跟踪您的所有请求和响应。

更重要的问题是:你想做什么?

The code is setting up an LWP::UserAgent object to masquerade as a browser used by a human being to bypass Google's spider detection mechanism. In doing so, it violates Google's Terms of Service:

5.3 You agree not to access (or attempt to access) any of the Services by any means other than through the interface that is provided by Google, unless you have been specifically allowed to do so in a separate agreement with Google. You specifically agree not to access (or attempt to access) any of the Services through any automated means (including use of scripts or web crawlers) and shall ensure that you comply with the instructions set out in any robots.txt file present on the Services.

59.39.92.148 is probably some compromised (or badly configured) open proxy in China. Setting $ua to use it is an attempt to hide the origin of the TOS violation.

Incidentally, you should be aware that the server at 59.39.92.148 will be able to log and track all your requests and responses should you decide to go down this route.

The more important question is: What are you trying to do?

凡间太子 2024-09-08 14:27:18

看起来像:使用 HTTP 代理打开“www.google.com”

Looks like: Open "www.google.com" using an HTTP Proxy

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