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;
 }
Beispiel #2
0
 public function test()
 {
     $xml = new \SimpleXMLElement(file_get_contents('http://www.bbc.com/vietnamese/index.xml'));
     $data = NULL;
     $html = new Htmldom();
     foreach ($xml->entry as $key => $val) {
         $link = (string) $val->link['href'];
         $obj = $html->file_get_html($link);
         if (!isset($obj->find('div[property=articleBody]')[0])) {
             $body = $obj->find('div.map-body')[0]->outertext;
         } else {
             $body = $obj->find('.story-body__inner')[0]->outertext;
         }
         $data[$link]['content'] = $body;
         $data[$link]['title'] = (string) $val->title;
         $data[$link]['description'] = (string) $val->summary;
         $data[$link]['category'] = (string) $val->category[1]['label'];
         $data[$link]['image'] = $obj->find('meta[property=og:image]')[0]->content;
     }
     dd($data);
     #dd($curl->get(array_keys($data)[0],"://",30,0));
     #$this->data['data'] = $data ;
     $this->data['content'] = 'layouts.admin.pages.local.test';
     return $this->output('admin', false);
 }
Beispiel #3
0
 /**
  * 
  * @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;
 }
Beispiel #6
0
 /**
  * Parsing the course html file.
  *
  * @param string $file
  * @param string $academic
  * @return array
  */
 protected function parsingFile($file, $academic)
 {
     $content = file_get_contents($file);
     // 確認是正確的學期,已防匯入舊資料
     if (!mb_strpos($content, $academic)) {
         return [];
     } else {
         if (mb_strpos($content, '教師未定')) {
             $this->comment("{$file} 此檔案含有「教師未定」課程,該檔案之所有課程已略過");
             return [];
         }
     }
     $html = $this->htmldom->str_get_html(str_ireplace('<font color=red>', '', $content));
     // 取得系所
     $department = $html->find('h1', 0)->plaintext;
     $department = trim(substr($department, strpos($department, ':') + 1));
     // 判斷是否為通通識課程
     $isGeneral = '通識教育中心' === $department;
     // 取得課程資料
     $courses = [];
     $pos = 0 + ($isGeneral ? 1 : 0);
     $lessons = $html->find('table tr');
     array_shift($lessons);
     foreach ($lessons as $lesson) {
         $t = explode(PHP_EOL, trim($lesson->children($pos + 3)->plaintext));
         $courses[] = ['dimension' => $isGeneral ? trim($lesson->children($pos)->plaintext) : null, 'code' => trim($lesson->children($pos + 1)->plaintext), 'name' => trim($t[0]), 'name_en' => trim($t[1]), 'professor' => str_replace(' ', ',', trim($lesson->children($pos + 4)->plaintext))];
     }
     return compact('department', 'isGeneral', 'courses');
 }
Beispiel #7
0
 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;
 }
Beispiel #8
0
 /**
  * 
  * @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;
 }
Beispiel #9
0
 /**
  * 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();
 }
Beispiel #10
0
 /**
  * @param string $str
  * @param bool $lowercase
  * @return object Dom
  */
 public function domFromString($str, $lowercase = true)
 {
     return parent::str_get_html($str, $lowercase);
 }