tu pourrais simuler la recherche direct sur le site via cURL (par exemple) et récupérer uniquement les infos qui t'intéresse via DOMDocument, mais bon y'a du travaille derrière, est ce que ca vaut vraiment le coup ? surtout que c'est pas terrible de récupérer les infos sur ce site de cette façon.je voudrais les diffuser gratuitement sur mon site, histoire de le remplir un peu plus...
je comprend bien que c'est pour toi, ou pour bosser, t'as tes raisons, mais vu que c'est trop légale, je te dis juste que c'est faisable, je t'ai cité les outils, à toi de joué après.Bah tu sais quand j'ai une idée en tête et que je n'y arrive pas je reste bloquer dessus jusqu'à ce que j'y arrive... Je déteste ne pas réussir et je ne demande qu'apprendre... Donc pour moi ça vaut le coup.
Après je comprends que toi tu aies autre chose à faire...
<?php
$url = 'http://www.boamp.fr';
$timeout = 10;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
if (preg_match('`^https://`i', $url))
{
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
}
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Utilisation de la méthode POST
curl_setopt($ch, CURLOPT_POST, true);
// Définition des champs et valeurs à envoyer
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'email' => '[email protected]'
));
$page_content = curl_exec($ch);
curl_close($ch);
echo $page_content;
?>
Merci
if (preg_match('`^https://`i', $url))
{
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
}
ca sent le copié collé <?php
$postfields = 'array';
$postfields["action"] = "submit";
$postfields["title"] = "Titre Test";
$postfields["url"] = "http://www.boamp.fr";
$postfields["recurl"] = "http://www.boamp.fr";
$postfields["description"] = "annuaire";
$postfields["email"] = "[email protected]";
//$postfields["add2newsletter"] = "1";
//url de la page de soumission
//ici mon annuaire (qui a un captcha donc inutile de tenter la soumission auto, c'est pour l'exemple)
$url = "http://www.boamp.fr/index.php?action=afficherFormRechAvancee";
$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;
?>
<?php
//creation du cookie
$fp = fopen("cookies.txt",'wb'); fclose($fp);
//on recupere le cookie
$url="http://e-marchespublics.com/";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE); curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt($ch, CURLOPT_USERAGENT, 'Opera/9.63 (Windows NT 5.1; U; fr) Presto/2.1.1');
curl_exec($ch);
curl_close($ch);
// on continue... 1er form
$url = "http://e-marchespublics.com/";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt($ch , CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Opera/9.63 (Windows NT 5.1; U; fr) Presto/2.1.1');
$postfields = array();
$postfields["type_avis"] = "aapc";
$postfields["departement"] = "67";
$postfields["submit"] = "SUBMIT";
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$result = curl_exec($ch);
curl_close($ch);
//fin du form
//On affiche le resultat:
echo $result;
?>
il faut rester dans la même session cURL, comme dans un navigateur, le curl_close correspond a fermer la fenêtrePas d'idées ?
<?php
//creation du cookie
$fp = fopen("cookies.txt",'wb'); fclose($fp);
//on recupere le cookie
$url="http://e-marchespublics.com/";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE); curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt($ch, CURLOPT_USERAGENT, 'Opera/9.63 (Windows NT 5.1; U; fr) Presto/2.1.1');
curl_exec($ch);
// on continue... 1er form
$url = "http://e-marchespublics.com/";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt($ch , CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Opera/9.63 (Windows NT 5.1; U; fr) Presto/2.1.1');
$postfields = array();
$postfields["type_avis"] = "aapc";
$postfields["departement"] = "67";
$postfields["submit"] = "SUBMIT";
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$result = curl_exec($ch);
//fin du form
//On affiche le resultat:
echo $result;
?>