Advertisement
Guest User

Untitled

a guest
Oct 11th, 2014
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. /**
  2. * Scrapes single news item from screenrant
  3. *
  4. * @param string $url
  5. * @return string
  6. */
  7. public function getSingleFromFirstShowing($url)
  8. {
  9. $item = $this->curl($url);
  10.  
  11. $crawler = new Crawler($item);
  12.  
  13. $html = $crawler->filter('.review p')->each(function (Crawler $node, $i)
  14. {
  15. $ht = trim($node->html());
  16.  
  17. //filter out unneeded html
  18. if (strpos($ht, 'class="technotags"')) return false;
  19. if (strpos($ht, 'title="Posts by')) return false;
  20.  
  21. return '<p>' . preg_replace('/<a.*?>(.*?)<\/a>/', '$1', $ht) . '</p>';
  22. });
  23.  
  24. return trim(implode('', $html));
  25. }
  26.  
  27. /**
  28. * Scrapes single news item from screenrant
  29. *
  30. * @param string $url
  31. * @return string
  32. */
  33. public function getSingleFromScreenRant($url)
  34. {
  35.  
  36. $text = '';
  37. $item = $this->curl($url);
  38.  
  39. $crawler = new Crawler($item);
  40.  
  41. $html = $crawler->filter('div[itemprop="articleBody"] p')->each(function (Crawler $node, $i)
  42. {
  43. $ht = trim($node->html());
  44.  
  45. //filter out unneeded html
  46. if (strpos($ht, 'contentjumplink')) return false;
  47. if (strpos($ht, 'type="button"')) return false;
  48. if (strpos($ht, 'type="hidden"')) return false;
  49. if (strpos($ht, 'AD BLOCK')) return false;
  50.  
  51.  
  52. if (strpos($ht, 'src='))
  53. {
  54. preg_match('/.*?<img src="(.*?)"/', $ht, $m);
  55.  
  56. if (isset($m[1]))
  57. {
  58. return "<img src='{$m[1]}' class='img-responsive'/>";
  59. }
  60. }
  61.  
  62. return '<p>' . preg_replace('/<a.*?>(.*?)<\/a>/', '$1', $ht) . '</p>';
  63. });
  64.  
  65. return trim(implode('', $html));
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement