title: Is there a PHP equivalent of Perl's WWW::Mechanize?
body: <p>I'm looking for a library that has functionality similar to Perl's <a href="http://search.cpan.org/dist/WWW-Mechanize/lib/WWW/Mechanize.pm#SYNOPSIS" rel="noreferrer">WWW::Mechanize</a>, but for PHP. Basically, it should allow me to submit HTTP GET and POST requests with a simple syntax, and then parse the resulting page and return in a simple format all forms and their fields, along with all links on the page.</p>
  
  <p>I know about CURL, but it's a little too barebones, and the syntax is pretty ugly (tons of <code>curl_foo($curl_handle, ...)</code> statements</p>
  
  <p><strong>Clarification:</strong></p>
  
  <p>I want something more high-level than the answers so far. For example, in Perl, you could do something like:</p>
  
  <pre><code># navigate to the main page
  $mech-&gt;get( 'http://www.somesite.com/' ); 
  
  # follow a link that contains the text 'download this'
  $mech-&gt;follow_link( text_regex =&gt; qr/download this/i );
  
  # submit a POST form, to log into the site
  $mech-&gt;submit_form(
      with_fields      =&gt; {
          username    =&gt; 'mungo',
          password    =&gt; 'lost-and-alone',
      }
  );
  
  # save the results as a file
  $mech-&gt;save_content('somefile.zip');
  </code></pre>
  
  <p>To do the same thing using HTTP_Client or wget or CURL would be a lot of work, I'd have to manually parse the pages to find the links, find the form URL, extract all the hidden fields, and so on. The reason I'm asking for a PHP solution is that I have no experience with Perl, and I could probably build what I need with a lot of work, but it would be much quicker if I could do the above in PHP.</p>