public static function getAddress($postalCode) { $params = ['cepEntrada' => $postalCode, 'tipoCep' => '', 'cepTemp' => '', 'metodo' => 'buscarCep']; $cacheKey = md5(self::CAHCE_POSTOFFICE_KEY . $postalCode); if (Cache::has($cacheKey)) { return Cache::get($cacheKey, new Response(true)); } $client = new Client(); $response = $client->request('POST', self::URL_POSTOFFICE_MOBILE, ['form_params' => $params]); if ($response->getStatusCode() === 200) { $result = $response->getBody(); $html = new Htmldom($result); $html->find('div[class=caixacampobranco]'); $responsePage = $html->find('span.respostadestaque'); $arrayResponse = []; $count = 0; foreach ($responsePage as $content) { $key = self::cleanString($html->find('span.resposta', $count)->plaintext); $arrayResponse[$key] = trim($content->plaintext); $count++; } $response = self::parseResponse($arrayResponse); Cache::put($cacheKey, $response, self::CACHE_MINUTES); } else { return new Response(true); } return $response; }
/** * * @return array */ public function getWords($word) { $suggestions = array(); $html = new Htmldom($this->base_url . $word); $listDiv = $html->find('.relevancy-list', 0); for ($i = 0; $i <= 5; ++$i) { $list = $listDiv->find('ul', $i); if (!$list) { continue; } $suggestions[$i]['data'] = array(); foreach ($list->find('li') as $element) { $data = array(); $linkElement = $element->find('a', 0); $linkSpan = $element->find('a', 0)->find('span', 0); $linkHref = $linkElement->href; $dataCategory = html_entity_decode($linkElement->getAttribute('data-category')); $data['link'] = $linkHref; $data['word'] = $linkSpan->innertext; $data['extra_data'] = $dataCategory; $suggestions[$i]['data'][] = $data; } } return $suggestions; }
/** * Execute the console command. * * @return mixed */ public function handle() { $this->startLog(); $team = Team::find(self::TEAM_ID); if ($team == null) { $this->error('Team with id: ' . self::TEAM_ID . ' not found'); exit; } $tournamentList = $this->tournament->getActiveScheduled(); if ($tournamentList->count() < 1) { $this->error('No tournaments'); exit; } $this->info('Tournaments count: ' . $tournamentList->count()); foreach ($tournamentList as $key => $tournament) { $this->info('Tournament ' . ++$key . ': ' . $tournament->name); $html = new Htmldom($tournament->link); $table = $html->find('table.match-day', 0); if ($table == null) { $this->error('No matchday info'); continue; } $gameList = $this->parseGameLinks($table, $team); $gameList = collect($gameList); $this->info('Games found: ' . $gameList->count()); foreach ($gameList->reverse() as $game) { $game->setTournamentId($tournament->id); $game->setTeamId($team->id); $game->setSearchTeamName($team->name); (new GameRepository())->addParsedGame($game); } } $this->endLog(); }
public function getWords($word) { $suggestions = array(); $html = new Htmldom($this->base_url . $word); $data = array(); foreach ($html->find('.meaning') as $element) { foreach (explode("/", $element->innertext) as $synonym) { $data['data'][] = array('word' => trim($synonym)); } $suggestions[] = $data; } return $suggestions; }
private function parseStats(Game $game, Htmldom $html) { $table = $html->find('table.season-list', 0); if (!$table) { $this->error('No stats table for game ' . $game->id); return null; } $stats = []; $team_class = $game->isHome() ? 'home_event' : 'away_event'; foreach ($table->find('tr') as $row) { $statRow = $row->find('td.' . $team_class, 0); if ($statRow) { array_push($stats, $this->parseAndDetermineStat($statRow)); } } return $stats; }
/** * * @return array */ public function getWords($word) { $suggestions = array(); $html = new Htmldom($this->base_url . $word); $list = $html->find('ul[class=words]', 0); $suggestions[0]['data'] = array(); if (!$list) { return FALSE; } foreach ($list->find('li') as $element) { $data = array(); $linkElement = $element->find('a', 0); $linkHref = $linkElement->href; $data['link'] = $linkHref; $data['word'] = $linkElement->innertext; $suggestions[0]['data'][] = $data; } return $suggestions; }
/** * Execute the console command. * * @return mixed */ public function handle() { $this->startLog(); $team = Team::find(self::TEAM_ID); if ($team == null) { $this->error('Team with id: ' . self::TEAM_ID . ' not found'); exit; } $html = new Htmldom($team->link); $team_table = $html->find('table.team-list', 0); if ($team_table == null) { $this->error('Team table not found on this page: ' . $team->link); exit; } $player_links = []; foreach ($team_table->find('p.player-name a') as $link) { if (isset($link->href)) { array_push($player_links, $link->href); } } if (count($player_links) < 1) { $this->error('No players found'); exit; } $this->comment('Found players: ' . count($player_links)); $bar = $this->output->createProgressBar(count($player_links)); foreach ($player_links as $link) { if (strpos($link, self::DOMAIN) === false) { $link = self::DOMAIN . $link; } $player = new Player(); $player->team_id = self::TEAM_ID; $player->mls_id = $this->parseIdFromUrl($link); $player_html = new Htmldom($link); if ($player_html == null) { continue; } $player_table = $player_html->find('table.adf-fields-table', 0); if ($player_table == null) { continue; } foreach ($player_table->find('tr') as $row) { $td1 = $row->find('td', 0); $td2 = $row->find('td', 1); if ($td1 != null && strpos($td1->innertext, 'Полное имя') !== false) { $player->name = $td2->plaintext; } if ($td1 != null && strpos($td1->innertext, 'Дата рождения') !== false) { $player->date_of_birth = Carbon::parse($td2->plaintext); } } $check_player = Player::where('mls_id', $player->mls_id)->where('name', $player->name)->where('team_id', $player->team_id)->where('date_of_birth', $player->date_of_birth)->first(); if ($check_player) { $player->id = $check_player->id; $player->update(); } else { $player->save(); } $img = $player_html->find('div#etab_player_div div.gray-box img', 0); if ($img != null && $img->src != null && strpos($img->src, self::DEFAULT_IMG) === false) { $src = $img->src; if (strpos($src, self::DOMAIN) === false) { $src = self::DOMAIN . $src; } copy($src, public_path() . '/img/avatars/players/' . $player->id . '.jpg'); } $bar->advance(); } $bar->finish(); $this->endLog(); }