✨ Ajoute la suppression d'annonce
This commit is contained in:
parent
0245bda600
commit
c231b7e26b
@ -10,6 +10,8 @@ class Account
|
||||
const LOGIN_URL = 'https://www.leboncoin.fr/beta/ajax/popins/connexion.html';
|
||||
const ACCOUNT_URL = 'https://compteperso.leboncoin.fr/account/index.html';
|
||||
const ADD_URL = 'https://www.leboncoin.fr/ai/form/0';
|
||||
const DELETE_URL = 'https://compteperso.leboncoin.fr/store/main?cmd=adservices';
|
||||
const UPLOAD_URL = 'https://www.leboncoin.fr/ai/photo_upload_ajax/0';
|
||||
|
||||
/** @var Client */
|
||||
protected $client;
|
||||
@ -102,11 +104,11 @@ class Account
|
||||
public function addDeal(Deal $deal)
|
||||
{
|
||||
try {
|
||||
// $t = date('YmdHis');
|
||||
// $log_folder = sprintf('%s/logs/%s', APP_DIR, $t);
|
||||
// mkdir($log_folder);
|
||||
$t = date('YmdHis');
|
||||
$log_folder = sprintf('%s/logs/%s', APP_DIR, $t);
|
||||
mkdir($log_folder);
|
||||
$crawler = $this->client->request('GET', self::ADD_URL);
|
||||
// file_put_contents(sprintf('%s/add.html', $log_folder), $crawler->html());
|
||||
file_put_contents(sprintf('%s/add.html', $log_folder), $crawler->html());
|
||||
$form = $crawler->selectButton('Valider')->form();
|
||||
$image0 = fopen(sprintf('%s/%s/image0.jpg', DEALS_DIR, $deal->getId()), 'r');
|
||||
$fields = $form->getPhpValues();
|
||||
@ -133,20 +135,36 @@ class Account
|
||||
'subject' => $deal->getSubject(),
|
||||
'body' => $deal->getBody(),
|
||||
'price' => $deal->getPrice(),
|
||||
// 'image0' => $image0,
|
||||
'image0' => $image0,
|
||||
'no_salesmen' => 1,
|
||||
'phone_hidden' => 1,
|
||||
]
|
||||
);
|
||||
$uri = self::UPLOAD_URL;
|
||||
$this->client->request('POST', $uri, $fields, [], ['Content-Type => multipart/form-data']);
|
||||
$uri = $form->getUri();
|
||||
// It needs to be done twice
|
||||
$this->client->request('POST', $uri, $fields, [], ['Content-Type => multipart/form-data']);
|
||||
$crawler = $this->client->request('POST', $uri, $fields, [], ['Content-Type => multipart/form-data']);
|
||||
// This one doesn't wor either -> redirect to Home
|
||||
file_put_contents(sprintf('%s/add-2.html', $log_folder), $crawler->html());
|
||||
$form = $crawler->selectButton('Valider mon annonce')->form();
|
||||
$crawler = $this->client->submit($form, ['accept_rule' => 1]);
|
||||
} catch (\Exception $e) {
|
||||
echo $e->getTraceAsString();
|
||||
}
|
||||
}
|
||||
|
||||
public function delete(Deal $deal)
|
||||
{
|
||||
$fields = [
|
||||
sprintf('selected_ads[%s]', $deal->getId()) => 'on',
|
||||
'cmd' => 'delete',
|
||||
'continue' => 'Continuer'
|
||||
];
|
||||
$crawler = $this->client->request('POST', self::DELETE_URL, $fields);
|
||||
// confirmation
|
||||
$form = $crawler->selectButton('Valider')->form();
|
||||
$crawler = $this->client->submit($form, ['delete_reason' => '1']);
|
||||
}
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ class Deal
|
||||
$crawler = $client->request('GET', $url);
|
||||
$deal = new self($crawler->filter('[data-savead-id]')->attr('data-savead-id'));
|
||||
$deal->setAccount($account);
|
||||
$deal->setSubject($crawler->filter('.item_imageCaption')->first()->text());
|
||||
$deal->setSubject($crawler->filter('h1')->first()->text());
|
||||
$deal->setCategory(array_search($crawler->filter('.breadcrumbsNav >ul >li')->eq(2)->text(), self::$categories));
|
||||
$deal->setType(self::TYPE_OFFER);
|
||||
$deal->setBody($crawler->filter('.properties_description')->first()->filter('p')->eq(1)->text());
|
||||
|
Loading…
Reference in New Issue
Block a user