title: How to parse a web site that uses `__dopostback` ajax call with curl and php
body: <p>Before someone says something or "jump," I would like to say that I have read:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/5658801/any-idea-on-how-to-scrape-pages-which-are-behind-dopostback">Any idea on how to scrape pages which are behind __doPostBack(&#39;...&#39;);?</a></li>
  <li><a href="https://stackoverflow.com/questions/3896852/dotnetnuke-php-simulating-a-remote-postback-using-curl">DotNetNuke, PHP, Simulating a remote postback using curl</a></li>
  <li><a href="https://stackoverflow.com/questions/11216910/scraping-html-with-javascript-postbacks">Scraping HTML with JavaScript postbacks</a></li>
  <li><a href="https://stackoverflow.com/questions/5384655/curl-post-data-to-asp-net-page">cURL post data to asp.net page</a></li>
  <li><a href="http://techclimber.blogspot.com.es/2009/03/php-curl-and-aspnet.html" rel="nofollow noreferrer">http://techclimber.blogspot.com.es/2009/03/php-curl-and-aspnet.html</a></li>
  </ul>
  
  <p>This is my function:</p>
  
  <pre><code>  function UolgetHtmlfromAjaxCallback($a_Params,$url) {
  
    $EVENTTARGET = $this-&gt;UolgetAtributoEventTarget($a_Params['s_EventTarget']);
    $s_smMaster = 'ctl00$cphSite$upModelo|'.$entries['target'];
    $VIEWSTATE = urlencode($a_Params['s_ViewState']);
  
    $options = array(
      CURLOPT_RETURNTRANSFER =&gt; true, // return web page
      CURLOPT_HEADER =&gt; false, // don't return headers
      CURLOPT_FOLLOWLOCATION =&gt; true, // follow redirects
      CURLOPT_ENCODING =&gt; "", // handle all encodings
      CURLOPT_USERAGENT =&gt; "spider", // who am i
      CURLOPT_AUTOREFERER =&gt; true, // set referer on redirect
      CURLOPT_CONNECTTIMEOUT =&gt; 120, // timeout on connect
      CURLOPT_TIMEOUT =&gt; 120, // timeout on response
      CURLOPT_MAXREDIRS =&gt; 10, // stop after 10 redirects
      CURLOPT_POST =&gt; true,
      CURLOPT_POSTFIELDS =&gt; 'ct100%24smMaster='.urldecode($s_smMaster).
                            '&amp;__EVENTTARGET='.urlencode($EVENTTARGET['target']).
                            '&amp;__EVENTARGUMENT='.urlencode('').
                            '&amp;__EVENTVALIDATION='.urlencode($s_Eventvalidation).
                            '&amp;__VIEWSTATE='.$VIEWSTATE.
                            '&amp;ct100%24txtBuscaNome='.$a_Params['ctl00_txtBuscaNome'].
                            '&amp;__ASYNCPOST=true'
                            );
  
    $ch = curl_init( $url );
    curl_setopt_array( $ch, $options );
    $result = curl_exec ($ch);
  
    return $result;
    }
  </code></pre>
  
  <p>The <code>$VIEWSTATE</code> is okay, and the <code>$EVENTTARGET</code> is an array with these values:</p>
  
  <pre><code>Array ( 
   [id] =&gt;          ctl00_cphSite_fichaTecnicaEditorial_rptCarrosFichaTecnica_ctl00_lbtnFichaTecnica 
   [target] =&gt; ctl00$cphSite$fichaTecnicaEditorial$rptCarrosFichaTecnica$ctl00$lbtnFichaTecnica ) 
  </code></pre>
  
  <p>I'm trying to use this code to scrape this website:</p>
  
  <p><a href="http://comparecar.uol.com.br/Modelo/Volvo-Xc60" rel="nofollow noreferrer">http://comparecar.uol.com.br/Modelo/Volvo-Xc60</a></p>
  
  <p>And I get the website, but not the car's information.</p>
  
  <p>I edit my own information.</p>
  
  <p>I'm working with Tamper Data and I found that the post uses different parameters:</p>
  
  <ul>
  <li><code>ctl00%24smMaster</code></li>
  <li><code>__EVENTTARGET</code></li>
  <li><code>__EVENTARGUMENT</code></li>
  <li><code>__VIEWSTATE</code></li>
  <li><code>__EVENTVALIDATION</code></li>
  <li><code>ctl00%24txtBuscaNome</code></li>
  <li><code>__ASYNCPOST</code></li>
  </ul>
  
  <p>And closes with an "="</p>