From 1c38a91d416716de27b5d5d287b0634f30ab48a3 Mon Sep 17 00:00:00 2001 From: Damien Calesse Date: Tue, 22 Jul 2014 20:02:40 +0200 Subject: [PATCH] Improve LeMondeDiploBridge.php --- bridges/MondeDiploBridge.php | 45 +++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/bridges/MondeDiploBridge.php b/bridges/MondeDiploBridge.php index f6abe7c..38f843b 100644 --- a/bridges/MondeDiploBridge.php +++ b/bridges/MondeDiploBridge.php @@ -10,29 +10,42 @@ * @description Returns most recent results from MondeDiplo. * @maintainer Pitchoule */ + class MondeDiploBridge extends BridgeAbstract{ public function collectData(array $param){ $link = 'http://www.monde-diplomatique.fr'; - + $html = file_get_html($link) or $this->returnError('Could not request MondeDiplo. for : ' . $link , 404); - - foreach($html->find('div[class=grid_10 alpha omega laune]') as $element) { - $item = new Item(); - $item->uri = 'http://www.monde-diplomatique.fr'.$element->find('a', 0)->href; - $NumArticle = explode("/", $element->find('a', 0)->href); - $item->title = $element->find('h3', 0)->plaintext; - $item->content = $element->find('div[class=crayon article-intro-'.$NumArticle[4].' intro]', 0)->plaintext; - $this->items[] = $item; - } - - foreach($html->find('div.titraille') as $element) { - $item = new Item(); + + foreach($html->find('div.laune') as $element) { + $item = new Item(); + $item->uri = 'http://www.monde-diplomatique.fr'.$element->find('a', 0)->href; + $item->title = $element->find('h3', 0)->plaintext; + $item->content = $element->find('div.dates_auteurs', 0)->plaintext. '
' .strstr($element->find('div', 0)->plaintext, $element->find('div.dates_auteurs', 0)->plaintext, true); + $this->items[] = $item; + } + + $liste = $html->find('div.listes', 0); // First list + foreach ($liste->find('li') as $e) { + + $item = new Item(); + $item->uri = 'http://www.monde-diplomatique.fr' . $e->find('a', 0)->href; + $item->title = $e->find('a', 0)->plaintext; + $item->content = $e->find('div.dates_auteurs', 0)->plaintext; + $this->items[] = $item; + } + + foreach($html->find('div.liste ul li') as $element) { + if ($element->getAttribute('class') != 'intrapub') { + $item = new Item(); $item->uri = 'http://www.monde-diplomatique.fr'.$element->find('a', 0)->href; $item->title = $element->find('h3', 0)->plaintext; - $item->content = $element->find('div.dates_auteurs', 0)->plaintext; + $item->content = $element->find('div.dates_auteurs', 0)->plaintext . '
' . $element->find('div.intro', 0)->plaintext; $this->items[] = $item; - } + } + } + } public function getName(){ @@ -47,4 +60,4 @@ class MondeDiploBridge extends BridgeAbstract{ return 21600; // 6 hours } } - +