Posted By

swizardb on 04/01/18


Tagged


Versions (?)

SNIPPET -2


 / Published in: PHP
 

snippet 2

  1. switch (TRUE)
  2. {
  3. // COMMENT 1
  4. case ($website_crawled[0]->website_address=='http://www.timesjobs.com' && $feature == 'job') :
  5. $client = new \GuzzleHttp\Client();
  6. $res = $client->get($import_url[0]->url);
  7.  
  8. if ($res->getStatusCode() == 200) {
  9.  
  10. // COMMENT 2
  11. $html_res = $res->getBody()->getContents();
  12.  
  13. // HINT :: https://stackoverflow.com/questions/4423272/how-to-extract-links-and-titles-from-a-html-page?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
  14.  
  15. //COMMENT 3
  16. $dom = new \DOMDocument;
  17.  
  18. //COMMENT 4
  19. @$dom->loadHTML($html_res);
  20. $params = $dom->getElementsByTagName('div');
  21.  
  22. foreach ($params as $param) {
  23. //COMMENT 5
  24. if (strpos($param->nodeValue, "\"@context\":\"http://schema.org\",\"@type\":\"JobPosting\"") > 0) {
  25.  
  26. //COMMENT 6
  27. $pattern = '%\"@context\":\"http://schema.org\",.*\"@type\":\"JobPosting\",.*\"hiringOrganization\":\"(.+?)\",.*?\"addressCountry\":\"(.+?)\".*?\"addressRegion\":\"(.+?)\".*?\"addressLocality\":\"(.+?)\".*?\"skills\":\"(.+?)\".*?\"title\":\"(.+)\".*\"qualifications\":\"(.+)\".*\"educationRequirements\":\"(.+)\".*\"industry\":\"(.+)\".*\"experienceRequirements\":\"(.+)\".*\"description\":\"(.+)\".*%' ;
  28.  
  29. preg_match($pattern, $param->nodeValue, $matches);
  30.  
  31. $job = new JobModel;
  32.  
  33. $job->user_id_fk = '1';
  34. $job->title = $matches[6] . ' job with ' . $matches[1] . ', ' . $matches[4] ;
  35. $job->cmp_name = $matches[1];
  36. $job->description = $matches[11] . '<p><a href="' . $import_url[0]->url . '" target="_blank">See original post on timesjobs.com</a></p>';;
  37. $job->job_location = $matches[4] . ' ' . $matches[3] . ' ' . $matches[2];
  38. $job->tags = $matches[5];
  39. $job->preferred_qualification = $matches[7];
  40. $job->skill = $matches[8];
  41. $job->website = $import_url[0]->url;
  42. $job->how_to_apply = $import_url[0]->url;
  43. $job->status = '0' ;
  44. $job->latitude = '0';
  45. $job->longitude = '0';
  46. $job->save();
  47. $job_id_fk = $job->id;
  48.  
  49. //COMMENT 7
  50. $list = DB::table('admin_url_crawled')
  51. ->where('id', $import_url[0]->id)
  52. ->update([
  53. 'imported' => '0',
  54. 'feature_id_fk' => $job_id_fk,
  55. ]);
  56. }
  57. }
  58. }
  59.  
  60. break;
  61. default:
  62. echo 'DEFAULT';
  63. }

Report this snippet  

You need to login to post a comment.