1

问题:使用 Web::Scraper 从 tor .onion 站点抓取

我想修改我的代码以连接到 .onion 站点。我相信我需要连接到 SOCKS5 代理,但不确定如何使用 Web::Scraper

现有代码:

use Web::Scraper;
my $piratelink=$PIRATEBAYSERVER.'/search/' . $srstring . '%20'. 's'.$sval[1].'e'.$epinum.'/0/7/0';
my $purlToScrape = $piratelink;
    my $ns = scraper {      
    process "td>a", 'mag[]' => '@href';
    process "td>div>a", 'tor[]' => '@href';
    process "td font.detDesc", 'sizerow[]' => 'TEXT';
};
my $mres = $ns->scrape(URI->new($purlToScrape));
4

1 回答 1

1

Web::Scraper如果您将 a 传递URI给抓取,则使用 LWP。

您可以使用其他一些使用 SOCKS 的 HTTP 库来获取 HTML,或者使用UserAgent来自 的共享变量Web::Scraper,您可以将 LWP 设置为使用 SOCKS 并将其作为代理传递。

use strict;
use LWP::UserAgent;
use Web::Scraper;

# set up a LWP object with Tor socks address
my $ua = LWP::UserAgent->new(
    agent => q{Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; YPC 3.2.0; .NET CLR 1.1.4322)},
);
$ua->proxy([qw/ http https /] => 'socks://localhost:9050'); # Tor proxy
$ua->cookie_jar({});

my $PIRATEBAYSERVER = 'http://uj3wazyk5u4hnvtk.onion';
my $srstring = 'photoshop';


my $piratelink=$PIRATEBAYSERVER.'/search/' . $srstring; # . '%20'. 's'.$sval[1].'e'.$epinum.'/0/7/0';

my $purlToScrape = $piratelink;
my $ns = scraper {      
    process "td>a", 'mag[]' => '@href';
    process "td>div>a", 'tor[]' => '@href';
    process "td font.detDesc", 'sizerow[]' => 'TEXT';
};

# override Scraper's UserAgent with our SOCKS LWP object
$Web::Scraper::UserAgent = $ua;

my $mres = $ns->scrape(URI->new($purlToScrape));

print $mres;

注意,您还需要安装 CPAN 模块LWP::Protocol::socks

于 2016-04-17T19:46:31.720 回答