Php CURL : se connecter à Leboncoin

WRInaute impliqué
Bonjour,

je souhaite récupérer le code html du site Leboncoin afin de le traiter et récuperer ce qui m'interesse.

Le problème c'est que je n'arrive meme pas à me connecter à Leboncoin. Ce me marque "You have been blocker". J'ai utilisé l'user agent de Google mais cela ne change rien. Avez-vous une astuce ? Merci d'avance

Voici le code :

PHP:
<?php

$url = 'https://www.leboncoin.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);

// Définition du header "User-Agent:"
// Simulation d'un Firefox 3.6.13
curl_setopt($ch, CURLOPT_USERAGENT, 'Googlebot/2.1 (+http://www.google.com/bot.html)');

$page_content = curl_exec($ch);

curl_close($ch);

echo $page_content;

?>
 
WRInaute accro
Fait encore un essai en changeant le UA de file_get_contents: https://stackoverflow.com/questions/2107759/php-file-get-contents-and-setting-request-headers
Ne met pas le UA de Google bot mais par exemple Chrome:
Code:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36

Si ça marche pas c'est ton IP bloquée ou autre astuce pour empêcher le scrap. Il faut tester en changeant d'IP avec un Proxy/VPN.

Edit: je viens de tester avec requests (Python):
Code:
<!--
Need permission to access data? Contact: DataAccess@datadome.co
-->
<html><head><title>You have been blocked</title><style>#cmsg{animation: A 1.5s;}@keyframes A{0%{opacity:0;}99%{opacity:0;}100%{opacity:1;}}</style></head><body style="margin:0"><p id="cmsg">Please enable JS and disable any ad blocker</p><script>var dd={'cid':'AHrlqAAAAAMAnSrqgIgbLNwAo6wcEw==','hsh':'05B30BD9055986BD2EE8F5A199D973'}</script><script src="https://ct.datadome.co/c.js"></script></body></html>

Ils utilisent https://datadome.co/ comme protection.
Apparemment la protection en JS, donc il faut utiliser Puppeteer / Proxy / VPN ou un plugin / bookmarklet pour ton browser.
 
Dernière édition:
WRInaute accro
Même avec Puppeteer ça marche pas (enfin il faut creuser plus) :

jMAlWqF.png
 
WRInaute impliqué
Puppeteer est en mesure de cliquer sur des élements il me semble. Pourquoi ne pas positionner la souris sur la checkbox du Captcha et ensuite cliquer dessus ? Ca te semble viable comme solution Spout ?
 
WRInaute impliqué
Je suis en train de tenter d'installer Puppeteer sous Ubuntu 16.04 mais j'ai une erreur d'installation que je n'arrive pas à régler :


npm WARN saveError ENOENT: no such file or directory, open '/root/puppeteertest/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/root/puppeteertest/package.json'
npm WARN puppeteertest No description
npm WARN puppeteertest No repository field.
npm WARN puppeteertest No README data
npm WARN puppeteertest No license field.

Merci d'avance de votre aide
 
WRInaute impliqué
Encore un problème visiblement :

(node:4711) UnhandledPromiseRejectionWarning: Error: Failed to launch chrome!
[0909/181224.284711:ERROR:zygote_host_impl_linux.cc(89)] Running as root without --no-sandbox is not supported. See http s://crbug.com/638180.


TROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md

at onClose (/root/puppeteertest/node_modules/puppeteer/lib/Launcher.js:333:14)
at Interface.helper.addEventListener (/root/puppeteertest/node_modules/puppeteer/lib/Launcher.js:322:50)
at emitNone (events.js:111:20)
at Interface.emit (events.js:208:7)
at Interface.close (readline.js:368:8)
at Socket.onend (readline.js:147:10)
at emitNone (events.js:111:20)
at Socket.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
(node:4711) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing insi de of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:4711) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
 
WRInaute impliqué
La solution :

remplacer

const browser = await puppeteer.launch()

par

const browser = await puppeteer.launch({args: ['--no-sandbox', '--disable-setuid-sandbox']})
 
WRInaute impliqué
En utilisant toujours Puppeteer, comment puis-je écrire du texte dans un input sans en connaitre son nom ?

J'ai cliqué avec la souris dessus, mais je ne sais pas comment le remplir. Etant donné que Leboncoin utilise une frame pour ce formulaire on ne connait pas les détails du code source.

HTML:
<iframe src="https://c.datadome.co/captcha/?initialCid=AHrlqAAAAAMAgCgqN8wsYEUAuQ0mEg%3D%3D&amp;hash=05B30BD9055986BD2EE8F5A199D973&amp;cid=xPWRn2aSDhK55qhYzwh8N1HGFa1PpS_8R4PHCQifd_" width="100%" height="100%" style="height:10      0vh;" frameborder="0" border="0" scrolling="yes"></iframe>

Merci d'avance
 
Discussions similaires
Haut