3
I’m trying to create a robot to automate a process, as post here: Automating process - Robot?
Given the suggestions, I am following using Curl. What is happening is the following: He can login, goes to the second page where has the form I want the POST to be done but it does not return anything. My question is whether I have to use a command that stores the login session. Because from what I am seeing it is returning a link that presents User and invalid password or Invalid session in the second POST. Follow my code:
// Inicia o cURL
$ch = curl_init();
// Define a URL original (do formulário de login)
curl_setopt($ch, CURLOPT_URL, 'http://site.com/consulta/index.php');
// Habilita o protocolo POST
curl_setopt ($ch, CURLOPT_POST, 1);
// Define os parâmetros que serão enviados
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'usuario=teste&senha=teste');
// Imita o comportamento patrão dos navegadores: manipular cookies
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
// Define o tipo de transferência (Padrão: 1)
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
// Executa a requisição
$store = curl_exec ($ch);
// Define uma nova URL para ser chamada (após o login)
curl_setopt($ch, CURLOPT_URL, 'http://site.com/consulta/forms.php');
// Habilita o protocolo POST
curl_setopt ($ch, CURLOPT_POST, 1);
// Define os parâmetros que serão enviados
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'campoNome=Joao');
// Executa a segunda requisição
$content = curl_exec ($ch);
//show information regarding the request
print_r(curl_getinfo($ch));
echo curl_errno($ch) . '-' .
curl_error($ch);
// Encerra o cURL
curl_close ($ch);
If I place a $content echo exits the form page, but without any information or fields typed..
I would need to run the script to give you an exact answer, do you know the Pastebin? is a repository where Voce can determine the maximum time that the file will become available, if possible create one with its complete code for me to run and point out its flaws..
– Vinícius Lara
@user3163662 The site and the user are not mine. I could not pass like this, but I understand that you could only see with the full. But at first, the requisition, the structure is right?
– ziad.ali
It seems to me that cookies are not going to the second page where you want to get the results, so you need to activate them. I did a search (I recommend to always do research in English, as it is easier to find answered questions) where the user wanted the same as you, see if it serves you: http://stackoverflow.com/questions/13241344/grabbing-data-from-a-website-with-curl-after-logging-in
– Vinícius Lara