title: Best way to crawl a page with multiple redirects
body: <p>I want to crawl the NCBI website and send request for protein local alignment available at this link:
  <a href="http://blast.ncbi.nlm.nih.gov/Blast.cgi?PROGRAM=blastp&amp;BLAST_PROGRAMS=blastp&amp;PAGE_TYPE=BlastSearch" rel="nofollow">http://blast.ncbi.nlm.nih.gov/Blast.cgi?PROGRAM=blastp&amp;BLAST_PROGRAMS=blastp&amp;PAGE_TYPE=BlastSearch</a></p>
  
  <p>I would like to know if I am able to submit a post request to this address and get the results which come in a new page, using PHP. There is also a issue there, before the final results are shown, the page undergoes multiple redirects  - you can test this situation using the following input which goes into the text area:</p>
  
  <pre><code>MHSSIVLATVLFVAIASASKTRELCMKSLEHAKVGTSKEAKQDGIDLYKHMFEHYPAMKKYFKHRENYTP
  ADVQKDPFFIKQGQNILLACHVLCATYDDRETFDAYVGELMARHERDHVKVPNDVWNHFWEHFIEFLGSK
  TTLDEPTKHAWQEIGKEFSHEISHHGRHSVRDHCMNSLEYIAIGDKEHQKQNGIDLYKHMFEHYPHMRKA
  FKGRENFTKEDVQKDAFFVNKDTRFCWPFVCCDSSYDDEPTFDYFVDALMDRHIKDDIHLPQEQWHEFWK
  LFAEYLNEKSHQHLTEAEKHAWSTIGEDFAHEADKHAKAEKDHHEGEHKEEHH
  </code></pre>
  
  <p>Here is my attempt:</p>
  
  <pre><code>$link = 'http://blast.ncbi.nlm.nih.gov/Blast.cgi?
  PROGRAM=blastp&amp;BLAST_PROGRAMS=blastp&amp;PAGE_TYPE=BlastSearch';
  
  $request = array(
      'http' =&gt; array(
          'method' =&gt; 'POST',
          'content' =&gt; http_build_query(array(
              'QUERY' =&gt; $aaText
              )
          ),
      )
  );
  
  $context = stream_context_create($request);
  $html = file_get_html($link, false, $context);
  echo $html;
  </code></pre>
  
  <p>This code gets me the initial page, as if no POST has been done.
  Thanks</p>
  
  <hr>
  
  <p>UPDATE</p>
  
  <p>I have tried one of the suggestions below - Goutte.</p>
  
  <p>Here is my new code:</p>
  
  <pre><code>require_once 'goutte.phar';
  
  use Goutte\Client;
  
  $client = new Client();
  
  $crawler = $client-&gt;request('GET', $link);
  
  $form = $crawler-&gt;selectButton('b1')-&gt;form();
  
  $crawler = $client-&gt;submit($form, array('QUERY' =&gt; $aaTest));
  
  echo $crawler-&gt;html();
  </code></pre>
  
  <p>Variable <code>$aaTest</code> is the protein sequence I gave above. The good part is: it posts, gets me the new page, but does not follow all the redirects. How can I make it follow all the redirects?</p>