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

时间:2016-04-17 05:37:22

标签: perl proxy scrape tor torsocks

问题:使用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));

1 个答案:

答案 0 :(得分:1)

Web::Scraper如果您将URI传递给scrape,则会使用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