SymfonyRules

bot_peliculas

Apr 23rd, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.64 KB | None | 0 0
  1. <?php
  2.  
  3. namespace AppBundle\Controller;
  4.  
  5. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  6. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  7. use Symfony\Component\DomCrawler\Crawler;
  8. use Symfony\Component\HttpFoundation\Request;
  9.  
  10. class DefaultController extends Controller
  11. {
  12.     /**
  13.      * @Route("/", name="homepàge")
  14.      */
  15.     public function pelisAction()
  16.     {
  17.         $wopelis = new Crawler(file_get_contents('http://www.wopelis.com/index'));
  18.  
  19.         $wopelis = $wopelis->filterXPath('//div[@data-model="peli"]')->each(function (Crawler $node) {
  20.             return $node->extract('data-id');
  21.         });
  22.  
  23.         $idPelis= array();
  24.         foreach ($wopelis as $pelis) $idPelis[] = $pelis[0];
  25.  
  26.         return $this->render('default/index.html.twig', [
  27.             'pelis' => $idPelis
  28.         ]);
  29.     }
  30.     /**
  31.      * @Route("/{id}", name="pelis")
  32.      */
  33.     public function indexAction($id)
  34.     {
  35.         $wopelis = new Crawler(file_get_contents('http://www.wopelis.com/peli.php?id=' .$id));
  36.  
  37.         $links = new Crawler(file_get_contents('http://www.wopelis.com/venlaces.php?npl='.$id));
  38.         $links = $links->filterXPath('//a[@class="enlace"]')->each(function (Crawler $node) {
  39.             return $node->extract('onclick');
  40.         });
  41.  
  42.         foreach ($links as $link) $linksClear[] = explode('\'',$link[0])[1];
  43.  
  44.         return $this->render('default/links.html.twig', [
  45.             'title' => $wopelis->filter('h1')->text(),
  46.             'plot' => $wopelis->filterXPath('//div[@class="info text"]')->text(),
  47.             'links' => isset($linksClear) ? $linksClear : null
  48.  
  49.         ]);
  50.     }
  51. }
Add Comment
Please, Sign In to add comment