Created
May 26, 2017 16:49
-
-
Save andreybolonin/a33985e9969f7cedcb09d462bf010ea8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace AppBundle\Provider; | |
use GuzzleHttp\Client; | |
use Symfony\Component\DomCrawler\Crawler; | |
use GuzzleHttp\Exception\ClientException; | |
/** | |
* Class IndeedProvider | |
* | |
* @package AppBundle\Provider | |
*/ | |
class IndeedProvider extends AbstractProvider | |
{ | |
/** | |
* @var string | |
*/ | |
public $url = [ | |
'https://www.indeed.com/find-jobs.jsp?cat=Accounting/Finance', | |
'https://www.indeed.com/find-jobs.jsp?cat=Administrative', | |
'https://www.indeed.com/find-jobs.jsp?cat=Arts/Entertainment/Publishing', | |
'https://www.indeed.com/find-jobs.jsp?cat=Banking/Loans', | |
'https://www.indeed.com/find-jobs.jsp?cat=Construction/Facilities', | |
'https://www.indeed.com/find-jobs.jsp?cat=Customer+Service', | |
'https://www.indeed.com/find-jobs.jsp?cat=Education/Training', | |
'https://www.indeed.com/find-jobs.jsp?cat=Engineering/Architecture', | |
'https://www.indeed.com/find-jobs.jsp?cat=Government/Military', | |
'https://www.indeed.com/find-jobs.jsp?cat=Healthcare', | |
'https://www.indeed.com/find-jobs.jsp?cat=Computer/Internet', | |
'https://www.indeed.com/find-jobs.jsp?cat=Hospitality/Travel', | |
'https://www.indeed.com/find-jobs.jsp?cat=Human+Resources', | |
'https://www.indeed.com/find-jobs.jsp?cat=Insurance', | |
'https://www.indeed.com/find-jobs.jsp?cat=Law+Enforcement/Security', | |
'https://www.indeed.com/find-jobs.jsp?cat=Legal', | |
'https://www.indeed.com/find-jobs.jsp?cat=Manufacturing/Mechanical', | |
'https://www.indeed.com/find-jobs.jsp?cat=Marketing/Advertising/PR', | |
'https://www.indeed.com/find-jobs.jsp?cat=Non-Profit/Volunteering', | |
'https://www.indeed.com/find-jobs.jsp?cat=Pharmaceutical/Bio-tech', | |
'https://www.indeed.com/find-jobs.jsp?cat=Real+Estate', | |
'https://www.indeed.com/find-jobs.jsp?cat=Restaurant/Food+Service', | |
'https://www.indeed.com/find-jobs.jsp?cat=Retail', | |
'https://www.indeed.com/find-jobs.jsp?cat=Sales', | |
'https://www.indeed.com/find-jobs.jsp?cat=Telecommunications', | |
'https://www.indeed.com/find-jobs.jsp?cat=Transportation/Logistics', | |
'https://www.indeed.com/find-jobs.jsp?cat=Upper+Management/Consulting', | |
]; | |
/** | |
* @param $pages | |
* @param $output | |
*/ | |
public function parse($pages, $output) | |
{ | |
foreach ($this->url as $category){ | |
$guzzle = new Client(); | |
// $response = $guzzle->get($category); | |
$html = file_get_contents($category); | |
$crawler = new Crawler($html); | |
// var_dump($crawler->count()); | |
$jobTitles = $crawler->filter('a.jobTitle'); | |
var_dump($jobTitles->count()); | |
exit; | |
foreach ($jobTitles as $key => $jobTitleFirst){ | |
$el = $guzzle->get($jobTitleFirst->getAttribute('href')); | |
$job = new Crawler($el->getBody()->getContents()); | |
$jobNames = $job->filter('div.result'); | |
$locations = $job->filter('div.row > span.location > span'); | |
foreach ($jobNames as $eq => $jobName){ | |
$name = trim($jobTitle->textContent); | |
$jobUrl = trim($jobName->getElementsByTagName('a')->iteam(0)->getAttribute('href')); | |
$location = trim($locations->eq($eq)->text()); | |
// $this->insert($name, $jobUrl, AbstractProvider::INDEED_PROVIDER, $location, null); | |
var_dump($name, $jobUrl, AbstractProvider::INDEED_PROVIDER, $location, null); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment