/** * {@inheritDoc} */ public function getAccounts(Bank $bank) { if (!$this->logged) { throw new \RuntimeException('Call login() first'); } $accounts = array(); $browser = $this->getBrowser(); $response = $browser->request()->getBody(); $dom = new \DomDocument(); @$dom->loadHTML($response); $xpath = new \DomXPath($dom); foreach ($xpath->query("//div[@class='dv']") as $div) { $xmlAccount = $xpath->query("a", $div); if ($xmlAccount->length > 0) { $id = preg_replace('/(.*)<br *\\/>(\\d*)<div.*/', '$2', $dom->saveXml($div)); $balance = str_replace(',', '.', $xpath->query("div", $div)->item(0)->textContent); $balance = preg_replace("/[\\xA0\\xC2 €]/", '', $balance); $account = new Account(); $account->setBank($bank)->setId($id)->setLabel($xmlAccount->item(0)->textContent)->setLink($xmlAccount->item(0)->getAttribute('href'))->setBalance($balance); $accounts[$account->getId()] = $account; } } return $accounts; }
/** * {@inheritDoc} */ public function getAccounts(Bank $bank) { // We need to be logged for this if (!$this->logged) { throw new \RuntimeException('Call login() first'); } // Get the accounts list $browser = $this->getBrowser(); $crawler = $browser->request('GET', $this->getUri('show-synthese')); // Loop on each of them $accounts = array(); $xmlAccounts = $crawler->filter('table#comptesEpargne tbody tr, table#comptes tbody tr'); foreach ($xmlAccounts as $account) { // Reset the crawler for further re-use $crawler->clear(); $crawler->add($account); // Crawl the account informations $cell1 = $crawler->filter('td.bdrT'); $cell2 = $crawler->filter('td.bdrL.num')->first(); $cell3 = $crawler->filter('td.bdrL.num')->eq(1); // Build a new account $account = new Account(); $account->setBank($bank); $account->setId($cell2->text()); $account->setLabel($cell1->text()); $account->setLink(str_replace('../..', $this->getUri('prefix'), $cell1->filter('a')->attr('href'))); $account->setBalance($this->parseAmount($cell3->text())); $accounts[] = $account; } return $accounts; }