下载安全图像中需要字符的文件

时间:2014-05-14 17:02:45

标签: perl www-mechanize

我正在尝试在此网站(http://www.bindingdb.org/bind/chemsearch/marvin/SDFdownload.jsp?all_download=yes)下载此文件(BindingDB_All_2014m4.tsv.zip)。我目前正在使用Perl和模块WWW :: Mechanize。但是,我无法以编程方式下载该文件,因为该站点要求我输入安全映像中的字符。我已经有一个帐户。以下是我正在使用的以下代码:

use strict;
use warnings;
use WWW::Mechanize;

#################################################
#### Downloads relevant files from BindingDB ####
#################################################

#### Get links to downloads ####
my $mech = WWW::Mechanize->new();
$mech->cookie_jar({});
my ($db, $sdf, $rel);
my ($dbfile, $sdffile, $relfile);
$mech->get("http://www.bindingdb.org/bind/chemsearch/marvin/SDFdownload.jsp?all_download=yes");
my $content = $mech->content();
if ($content =~ /\<li\>\<a\shref\=\"(.*?)\"\>BindingDB\_All\_20/)
{
    $db = $1;
    $dbfile = &file ($db);
}
if ($content =~ /\<li\>\<a\shref\=\"(.*?)\"\>BindingDB\_All\_3D\_20/)
{
    $sdf = $1;
    $sdffile = &file ($sdf);
}
if ($content =~ /\<li\>\<a\shref\=\"(.*?)\"\>BindingDB\_CID\.txt/)
{
    $rel = $1;
    $relfile = &file ($rel);
}

#### Download BindingDB_All.tsv ####
$mech->get("http://www.bindingdb.org$db");
my $clone = $mech->clone();
$clone->cookie_jar({});
my $image = $clone->find_image( url_regex => qr/simpleImg/ );
if ($image)
{
    $clone->get($image->url, ':content_file' => '/home/wallakin/GLASS/ligand/bindingdb/images/simpleImg.jpg');
}

print "Please copy down the characters in the image, then close it.\n";
display /home/wallakin/GLASS/ligands/bindingdb/images/simpleImg.jpg`;
print "Enter the characters: ";

my $email = 'some email';
my $password = 'some password';
my $answer = <STDIN>;

$mech->form_number(1);
$mech->field( 'email'=> $email );
$mech->field( 'password' => $password );
$mech->field( 'answer'=> $answer );
$mech->submit();

print "Downloading BindingDB_All.tab.zip\n";
$mech->get("http://www.bindingdb.org/bind/downloads/BindingDB_All_2014m4.tsv.zip");

我收到以下错误:

Error GETing http://www.bindingdb.org/bind/chemsearch/marvin/SDFdownload.jsp?dimension=&email=something&password=something&answer=something%0A&download_file=%2Fbind%2Fdownloads%2FBindingDB_All_2014m4.tsv.zip: Internal Server Error at get_bindingdb.pl line 56.

问题出现在$ mech-&gt; submit()上,过去几天我一直在努力弄清楚为什么这不起作用。需要注意的是,这纯粹是为了学术目的,而不是与机器人相关的活动。我希望得到任何反馈,并提前感谢!

0 个答案:

没有答案