Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.91 KB | None | 0 0
  1. <?php
  2. require "phpQuery-onefile.php";
  3.  
  4. function get_data($url)
  5. {
  6. $ch = curl_init();
  7. $timeout = 5;
  8. curl_setopt($ch,CURLOPT_URL,$url);
  9. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  10. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
  11. curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:7.0.1) Gecko/20100101 Firefox/7.0.1');
  12. $data = curl_exec($ch);
  13. curl_close($ch);
  14. return $data;
  15. }
  16.  
  17. $url = 'https://bankir.ru/kurs/';
  18.  
  19. // $pattern = '#<table class="kurs_table_small.+?</table>#s';
  20. // preg_match($pattern, $file, $matches);
  21. // print_r($matches);
  22.  
  23. $doc = phpQuery::newDocument(get_data($url));
  24. $tbl = $doc->find('.kurs_table_small > tbody');
  25. $z = 0;
  26. foreach ($tbl->find('tr') as $tr) {
  27.     $pq = pq($tr);
  28.     $img = $pq->find("img")->attr("src");
  29.     if ($z == 0){
  30.         echo $pq->text()."<br />";
  31.     }
  32.     else{
  33.         echo $pq->text()."<img src='https://bankir.ru{$img}'>"."<br/>" ;
  34.     }
  35.  
  36.     $z++;
  37. }
  38. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement