Curl PHP - Retrieving html from page

Asked

Viewed 901 times

1

Hello,

I’m training this URL. Can you tell me why the following section doesn’t work?

<html>
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <?php
    $cURL = curl_init('http://fiesselecaoaluno.mec.gov.br/consulta/curso');
    curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
    $dados = array(
        'opcaoProcurar' => 'I',
        'noIes' => '10',
    );
    curl_setopt($cURL, CURLOPT_POST, true);
    curl_setopt($cURL, CURLOPT_POSTFIELDS, $dados);
    curl_setopt($cURL, CURLOPT_REFERER, 'http://fiesselecaoaluno.mec.gov.br/consulta/curso');
    $resultado = curl_exec($cURL);
    curl_close($cURL);
    echo $resultado;
    ?>
</body>

I wanted to get the html with Curl, but only dps of it have filled out the form correctly. Any hints?

Has something to do with the page form, or is it because it is ajax and Curl does not work for this ?

  • In what environment are you using this script?

  • How is the HTML of the form?

  • I just reviewed the form and from what I saw, it is Ajax and would not accept the logic of the script you made.

  • I was just going to enter the url to which forwards the post, thank you very much

1 answer

0


The service you’re doing post is wrong, must be http://fiesselecaoaluno.mec.gov.br/consulta/consulta:

$cURL = curl_init('http://fiesselecaoaluno.mec.gov.br/consulta/consulta');
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
$dados = array(
    'opcaoProcurar' => 'I',
    'noIes' => '10',
);
curl_setopt($cURL, CURLOPT_POST, true);
curl_setopt($cURL, CURLOPT_POSTFIELDS, $dados);
curl_setopt($cURL, CURLOPT_REFERER, 'http://fiesselecaoaluno.mec.gov.br/consulta/curso');
$resultado = curl_exec($cURL);
curl_close($cURL);
echo $resultado;

In this case, can you see what service is going to be done post by the action of the form

  • That was it, solved.

  • just a doubt, it writes the tables on the page, have as I recover the data from ajax without needing to copy all the html of the page ?

  • @Mauriciomaletta now I’m not on the computer, but what data? You didn’t want html?

  • no, I found some cool functions: loadHTML() and getelementsbytagname(). I think you can do with them, I want to take the data from the tables and put it in an array, to keep the table structure, but without the html code.

  • @Mauriciomaletta, but you already have html within $result, but how do echo for the browser (browser) it randeriza that... You can verify this if you do echo htmlentities($resultado); in the end

  • I just wanted to clear html, it looks like I’ll have to use regular expressions

  • @Mauriciomaletta may use http://simplehtmldom.sourceforge.net/

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.