I wrote this small script that uploads a picture to TinyPic.com using WWW::Mechanize, but I've never been that good with pattern matching and I'm trying to extract the URL to the image after its been uploaded from the pages contents. Script Code
use strict; use WWW::Mechanize; use HTTP::Cookies; my $mech = WWW::Mechanize->new( stack_depth => 1, agent =>"Mozilla/5.0 + (X11; U; Linux i68+6; en-US; rv:1.7) Gecko/20040918 Firefox/0.9.3 ") +; my $pic = "C:\/LV3.JPG"; $mech->cookie_jar( HTTP::Cookies->new() ); $mech->get("http://tinypic.com"); if($mech->content() =~ /UPLOAD NOW/ ){ print "TinyPic loaded... "; $mech->form_name("upload_form"); $mech->field('the_file' => $pic); $mech->submit(); }
and this is the mech->content from the page after it's been uploaded
<html> <head> <meta http-equiv="Content-Type" content="text/html; char +set=iso-8859-1" /> <meta name="description" content="TinyPic, a Photobucket + Video and Image Hosting company" /> <meta name="keywords" content="images, photos, videos, m +yspace, ebay, video hosting, photo hosting" /> <title>TinyPic - Share The Experience!&trade;</title> <link href="http://static.tinypic.com/s/stylesheet.css" +rel="stylesheet" type="text/css" /> </head> <body> <table width="100%" height="95%"> <tr> <td valign="middle" align="center"> <form name="myform" method="post" action="http://tiny +pic.com/index.php" target="_parent"> <input type="hidden" name="pic" value="86gjua9" /> <input type="hidden" name="s" value="1"> <input type="hidden" name="ival" value="11" /> <input type="hidden" name="type" value=".jpg" /> <input type="hidden" name="domain_lang" value="en" /> <script language="javascript">document.myform.submit( +)</script> </form> <strong><a href="http://tinypic.com/view.php?pic=86gj +ua9&s=1" target="_blank">Click here</a> to view your image</strong> </td> </tr> </table> </body> </html>
http://tinypic.com/view.php?pic=86gjua9 is what I'm trying to get it to pull from the page content

In reply to Pattern Matching Q? by 80degreez

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, details, 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, summary, 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.