#!/usr/bin/perl use strict; use WWW::Mechanize; open (FILE, "data.txt"); my $input; while ($input = ){ chomp $input; #download PDB html page my $url = "http://www.rcsb.org/pdb/explore.do?structureId="."$input"; my $mech = WWW::Mechanize->new( autocheck => 1 ); $mech->get( $url ); #write extracted data to an output file (.html) my $file = "$input".".html"; print "$file"; use Data::Dumper; open (OUTFILE, "> $file"); print OUTFILE Dumper($mech); close(OUTFILE); #download the link (FASTA sequence) my $linkname = "fileFormat=FASTA&compression=NO&structureId="."$input"; my @links = $mech->find_all_links( url_regex => qr/$linkname/ ); for my $link ( @links ) { my $url = $link->url_abs; my $filename = $url; $filename =~ s[^.+/][]; print "Fetching $url"; $mech->get( $url, ':content_file' => $filename ); print " ", -s $filename, " bytes\n"; } } close (FILE);