加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

为什么Perl允许使用TOR而不是https的http网站?

发布时间:2020-12-15 23:37:25 所属栏目:大数据 来源:网络整理
导读:如果它是一个https网站,我很难使用perl通过TOR访问网站,但如果它是一个http网站则不会. #!/usr/bin/perluse strict;use WWW::Mechanize;use LWP::Protocol::socks;use LWP::Protocol::https;use utf8;my $mech = WWW::Mechanize-new(timeout = 60*5);$mech-p
如果它是一个https网站,我很难使用perl通过TOR访问网站,但如果它是一个http网站则不会.

#!/usr/bin/perl
use strict;

use WWW::Mechanize;
use LWP::Protocol::socks;
use LWP::Protocol::https;
use utf8;

my $mech = WWW::Mechanize->new(timeout => 60*5);
$mech->proxy(['http','https'],'socks://localhost:9150');
$mech->get("https://www.google.com");

我收到错误消息:错误GETing https://www.google.com:状态读取失败:第10行的文件描述符错误,“其中第i10行是程序的最后一行.

在TOR浏览器中,我可以成功查看:“https://www.google.com”,端口为9150.
我正在使用ActivePerl 5.16.2; Vadalia 0.2.21和Tor 0.2.3.25.
我有一台Windows机器,我的主要互联网浏览器是Mozilla.

我尝试使用命令安装包:

cpan LWP::UserAgent
ppm install LWP::Protocol::https
cpan LWP::Protocol::https
ppm install LWP::Protocol::socks
cpan LWP::Protocol::socks
ppm install Mozilla::CA
ppm install IO::Socket::SSL
ppm install Crypt::SSLeay
cpan Crypt::SSLeay

感谢您的任何帮助!请告诉我是否有任何其他信息可以提供.

解决方法

前一段时间,我找到了通过使用WWW :: Curl :: Easy来获取这些类型网站的https网站的方法,因为使用LWP我发现了同样的问题.
之后,我将所有html保存在文件中并使用WWW :: Mechanzie或HTML :: TreeBuilder进行解析.

如果你想要与帖子表格等网站进行更多互动,这个解决方案可能会更加繁琐,因为你需要与curl进行互动.


package Curl;

use warnings;
use WWW::Curl::Easy;
use WWW::UserAgent::Random;


my $curl = WWW::Curl::Easy->new;
my $useragent = rand_ua("browsers");
my $host = 'localhost';
my $port = '9070';

my $timeout = '20';
my $connectTimeOut= '20';


&init;


sub get
{
        my $url = shift;

        $curl->setopt(CURLOPT_URL,$url);
        my $response_body;
        $curl->setopt(CURLOPT_WRITEDATA,$response_body);


        my $retcode = $curl->perform;

        if ($retcode == 0) {
                print("Transfer went ok Http::Code = ".$curl->strerror($retcode)."n");
                my $response_code = $curl->getinfo(CURLINFO_HTTP_CODE);
                # judge result and next action based on $response_code


                return $response_body;
        } else {
                # Error code,type of error,error message
                print("An error happened: $retcode ".$curl->strerror($retcode)." ".$curl->errbuf."n");
                return 0;
        }


}



sub init
{
        #setejem el proxy
        $curl->setopt(CURLOPT_PROXY,"$host:".$port);
        $curl->setopt(CURLOPT_PROXYTYPE,CURLPROXY_SOCKS4);

        #posem les altres dades
        $curl->setopt(CURLOPT_USERAGENT,$useragent);
        $curl->setopt(CURLOPT_CONNECTTIMEOUT,$connectTimeOut);
        $curl->setopt(CURLOPT_TIMEOUT,$timeout);
        $curl->setopt(CURLOPT_SSL_VERIFYPEER,0);
        $curl->setopt(CURLOPT_HEADER,0);
}

希望对你有帮助!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读