使用Curl自动登录,作为输入字段之一[关闭]

问题描述 投票:-5回答:1

我正在尝试使用Curl在此站点上自动登录:https://online.hinode.com.br,并且必须自动填写顾问ID以及始终相同的状态,登录后应重定向到特定产品页面。但是,我测试的代码没有去任何地方!没有错误,html没有加载...我认为应该是这个选择字段,我不知道。

码:

<?php
// Start cURL
$ch = curl_init();
// Define the original URL (of the login form)
curl_setopt($ch, CURLOPT_URL, 'https://online.hinode.com.br/');
// Enable POST protocol
curl_setopt ($ch, CURLOPT_POST, 1);
// Define the parameters that will be sent (user and password for example)
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'loja_consultor=fulano&estado=SP');
// Imitate the boss behavior of browsers: handle cookies
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
// Set the transfer type (Padrão: 1)
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
// Execute the requisition
$store = curl_exec ($ch);
// Define a new URL to be called (after login)
curl_setopt($ch, CURLOPT_URL, 'https://online.hinode.com.br/detalhes.asp?IdProduto=769&ssp=830852727SSP20171218HP115020');
// Execute the second request
$content = curl_exec ($ch);

//关闭cURL curl_close($ ch);

提前致谢!

enter image description here

enter image description here

enter image description here

enter image description here

php html curl dom
1个回答
0
投票

这将有效:

<?php
$cookie="cookie.txt";
$login_url = "https://online.hinode.com.br/loja_valida.asp";
$target_url="https://online.hinode.com.br/detalhes.asp?IdProduto=1294&ssp=1044632862SSP20171218HP180256";
$useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";

$field['loja_consultor'] = '228621';
$field['estado'] = 'SP';
$field['acessar'] = 'Acessar';

$datafield = http_build_query($field);

$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_URL, $login_url);
curl_setopt ($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $datafield);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

curl_exec($ch);

curl_setopt($ch, CURLOPT_URL, $target_url);
$ket_qua = curl_exec($ch);

echo $ket_qua;

curl_close($ch);
?>
© www.soinside.com 2019 - 2024. All rights reserved.