Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
use strict; use warnings; use WWW::Mechanize (); use String::Approx 'adist'; main( @ARGV ); exit; sub main { initialize( @_ ); for my $part_number ( @_ ) { print part_spec( $part_number ) . "\n"; } } sub initialize { } sub part_spec { my $part_number = shift; my ( $bare_number ) = $part_number =~ /^(ST\d+)/; my $www = WWW::Mechanize->new; $www->get( 'http://www.seagate.com/support/disc/' ); $www->submit_form( form_number => 2, fields => { modelcode => $bare_number } ); my $spec_page; for my $test ( qr/.support.disc.specs.+$part_number/i, qr/.support.disc.specs.+$bare_number/i ) { my @candidates = $www->find_all_links( url_regex => $test ); if ( 1 == @candidates ) { $spec_page = $candidates[0]; last; } elsif ( @candidates ) { my @dists = map adist( lc( $part_number ), lc( $_->url ) ), @candidates; $spec_page = $candidates[ ( sort { $dists[$a] <=> $dists[$b] } 0 .. $#dists )[ 0 ] ]; last; } } $www->get( $spec_page->URI ); my ( $capacity, $rpm, $access_time, $desc ) = $www->content =~ /\b ([\d.]+) \s* GB .+? \b (\d+) \s* rpm .+? \b ([\d.]+) \s* ms .+? ((?-s:ST-\d+.+))/xs; return "Desc=$desc\n" . "Capacity=$capacity\n" . "RPM=$rpm\n" . "Access time=$access_time\n"; } sub render_html { require HTML::FormatText; my $html = shift; return HTML::FormatText->format_string( $html ); }

In reply to Lookup seagate hard drives by model number by diotalevi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (5)
    As of 2020-01-23 23:38 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Notices?