Advertisement
cecepsuwanda

class_curl

Jan 15th, 2018
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.65 KB | None | 0 0
  1. <?php
  2. require_once('php/phpQuery.php');
  3. class get_data{
  4.  
  5. private $url;
  6. private $data_artikel;
  7. private $data_title;
  8. private $data_img;
  9.  
  10. function __construct($url) {
  11.        $this->url=$url;
  12.        $html = $this->curlget($url);
  13.        $doc = phpQuery::newDocument($html);
  14.        $this->data_title  = $doc->find('title:first')->text();
  15.        $this->data_artikel =  $doc->find('section[class=standardArticle]')->text();
  16.        $this->data_img = $doc->find('div[class=articleImage]')->find('img')->attr('src');
  17. }
  18.  
  19.  
  20. private function curlget($url){
  21.  
  22.     $curl = curl_init();
  23.     $USERA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36";
  24.     curl_setopt($curl, CURLOPT_USERAGENT, $USERA);
  25.     curl_setopt($curl, CURLOPT_URL, $url);
  26.     curl_setopt($curl, CURLOPT_FOLLOWLOCATION,false);
  27.     curl_setopt($curl, CURLOPT_HEADER, 0);
  28.     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  29.     curl_setopt($curl, CURLOPT_ENCODING, "");
  30.     curl_setopt($curl, CURLOPT_TIMEOUT, 15);
  31.      $curldata = curl_exec($curl);
  32.     return $curldata;
  33. }
  34.  
  35. public function get_title(){
  36.    return $this->data_title;
  37. }
  38. public function get_artikel(){
  39.    return $this->data_artikel;
  40. }
  41. public function get_img(){
  42.    return $this->data_img;  
  43. }
  44. }
  45. $dataku = new get_data("https://www.premierleague.com/news/591418");
  46.  
  47.  
  48. ?>
  49.  
  50. <!DOCTYPE html>
  51. <html>
  52. <head>
  53.     <title>asa</title>
  54. </head>
  55. <body>
  56.     <img style="width: 200px;height: 200px;" src=<?php echo $dataku->get_img(); ?>>
  57.     <h3><?php echo $dataku->get_title(); ?></h3>
  58.     <p><?php echo $dataku->get_artikel(); ?></p>
  59. </body>
  60. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement