private function extract_profiles() { $county = MsCounty::where('status', '=', '1')->orderBy('county_id')->first(); if ($county) { if (App::runningInConsole()) { fwrite(STDOUT, "=========== Extract Profiles : " . $county->name . PHP_EOL); } $curr_county_id = $county->county_id; echo $curr_county_id . "\n"; $html = Storage::get('sexoffenders/_html/' . str_slug($this->state->state_name) . '/' . $curr_county_id . '.html'); $link_crawler = new Crawler($html); try { $table = $link_crawler->filter('h4')->nextAll(); $links = $table->filter('a')->extract(array('href')); foreach ($links as $link) { $url = str_replace("./", $this->url_base, $link); $hash = md5($url); $profile = MsProfile::firstOrNew(array('hash' => $hash)); $profile->url = $url; $profile->hash = $hash; $profile->county_id = $curr_county_id; $profile->save(); unset($profile); } $status = 3; } catch (\InvalidArgumentException $e) { $status = 4; } $county = MsCounty::firstOrNew(['county_id' => $curr_county_id]); $county->status = $status; $county->save(); $this->state->records_expected = MsProfile::count(); $this->state->save(); // unset($html); unset($link_crawler); unset($county); // $this->extract_profiles(); } else { if (App::runningInConsole()) { fwrite(STDOUT, "=========== Extract DONE" . PHP_EOL); } $this->process_profiles(); } }