<?php
try {
$form = '
<form enctype="multipart/form-data" name="formPV" id="formPV" method="POST" action="http://goo.gl/cjwe8E " target="output">
<input type="text" id="PVlatitude" name="latitude" value="43.558422"><br>
<input type="text" id="PVlongitude" name="longitude" value="4.069032"><br>
Base : <input type="text" id="pv_database" name="pv_database" value="PVGIS-CMSAF"><br>
Modules : <select name="pvtechchoice"><option value="crystSi">Crystalline silicon</option><option value="CIS">CIS</option><option value="CdTe">CdTe</option><option value="Unknown">Unknown/Other</option></select><br>
Puissance : <input type="text" id="peakpower" name="peakpower" value="3">kWp<br>
Perte : <input type="text" id="efficiency" name="efficiency" value="14">%<br>
Montage : <select name="mountingplace"><option value="free">Free-standing</option><option value="building">Building integrated</option></select><br>
Inclinaison : <input type="text" name="angle" id="PVangle" value="30">°<br>
Azimuth : <input type="text" name="aspectangle" id="PVaspectangle" value="30">°<br>
Sortie : <input type="radio" name="outputchoicebuttons" value="window" onclick="nontextclicked_PV(this);" checked ><br>
Hidden regionname : <input type="text" name="regionname" value="europe"><br>
Hidden language : <input type="text" name="language" value="en_en" id="PVlanguage"><br>
<input type="submit" name="sbutton" id="PVchoicesubmit" value="Calculate" />
</form>
';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $form);
curl_setopt($curl, CURLOPT_COOKIESESSION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$resultat = curl_exec($curl);
echo "resultat : ";
print_r($resultat);
curl_close($curl);
} catch (Exception $e) {
echo $e->getMessage();
echo "<br>";
echo $e->getTraceAsString();
}
?>
Correction chef?! curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'key' => 'XXX',
'date' => date('Y-m-d'),
'frequence'=>'1'
));
Cet exemple dit à ma connexion curl $ch que je remplis le formulaire de sa page avec XXX pour l'input key, la date pour la date et 1 pour la fréquence. Donne lui les valeurs directement et pas le formulaire html ! <?php
$postfields = array();
$postfields["action"] = "submit";
$postfields["PVlatitude"] = "43.558422";
$postfields["PVlongitude"] = "4.069032";
$postfields["pv_database"] = "PVGIS-CMSAF";
$postfields["pvtechchoice"] = "crystSi";
$postfields["peakpower"] = "3";
$postfields["efficiency"] = "14";
$postfields["mountingplace"] = "building";
$postfields["PVangle"] = "30";
$postfields["PVaspectangle"] = "30";
$postfields["outputchoicebuttons"] = "window";
$postfields["regionname"] = "europe";
$postfields["language"] = "en_en";
$url = "http://goo.gl/cjwe8E";
$useragent = "Mozilla/5.0";
$referer = $url;
//Initialise une session CURL
$ch = curl_init($url);
//CURL options
curl_setopt($ch, CURLOPT_POST, 1);
//On poste les données du tableau $postfields
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
//On définit un useragent ici Mozilla/5.0
//souvent les bots se font passés pour googlebot ce qui finalement est stupide
//On passe donc un useragent banal
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
//On passe un referrer ici on passe la même page $url
curl_setopt($ch, CURLOPT_REFERER, $referer);
//on récupère le contenu de la page de résultat de la soumission dans une chaine
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// en cas de redirection (facultatif ici)
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//Page de résultats et fermeture de session
$result = curl_exec($ch);
curl_close($ch);
//on peut faire un echo du résultat obtenu
echo $result;
?>
Ca n'affiche rien non plus pour le moment, ainsi :<?php
$postfields = array();
$postfields["action"] = "submit";
$postfields["MAX_FILE_SIZE"] = "10000";
$postfields["pv_database"] = "PVGIS-CMSAF";
$postfields["pvtechchoice"] = "crystSi";
$postfields["peakpower"] = "3";
$postfields["efficiency"] = "14";
$postfields["mountingplace"] = "building";
$postfields["angle"] = "35";
$postfields["aspectangle"] = "10";
$postfields["horizonfile"] = "";
$postfields["outputchoicebuttons"] = "window";
$postfields["sbutton"] = "Calculate";
$postfields["outputformatchoice"] = "window";
$postfields["optimalchoice"] = "";
$postfields["latitude"] = "43.570274";
$postfields["longitude"] = "4.064435";
$postfields["regionname"] = "europe";
$postfields["language"] = "en_en";
$url = "http://goo.gl/cjwe8E";
$useragent = "Mozilla/5.0";
$referer = $url;
//Initialise une session CURL
$ch = curl_init($url);
//CURL options
curl_setopt($ch, CURLOPT_POST, 1);
//On poste les données du tableau $postfields
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
//On définit un useragent ici Mozilla/5.0
//souvent les bots se font passés pour googlebot ce qui finalement est stupide
//On passe donc un useragent banal
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
//On passe un referrer ici on passe la même page $url
curl_setopt($ch, CURLOPT_REFERER, $referer);
//on récupère le contenu de la page de résultat de la soumission dans une chaine
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// en cas de redirection (facultatif ici)
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//Page de résultats et fermeture de session
$result = curl_exec($ch);
curl_close($ch);
//on peut faire un echo du résultat obtenu
echo $result;
//var_dump($result)
?>
/$lignes = explode("\n",$result);
if(!is_array($lignes)) { die('Ma variable résultat n a pas renvoyé un tableau exploitable'); }
$lignes8 = explode("\t",$lignes[8]);
echo trim($lignes8[2]);
Merci!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!