Advertisement
Guest User

phpquery4

a guest
Feb 3rd, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. require 'phpQuery.php';
  5. $url = curl_init();
  6. curl_setopt($url, CURLOPT_URL, "http://theory.phphtml.net/exercises/advanced/php/parsing/zadachi-na-poetapnyj-parsing-i-metod-pauka/1/index.php");
  7. curl_setopt($url, CURLOPT_RETURNTRANSFER, 1);
  8. curl_setopt($url, CURLOPT_FOLLOWLOCATION, 1);
  9. $str = curl_exec($url);
  10. $pq = phpQuery::newDocument($str);
  11. $links = $pq->find('#menu a');
  12.  
  13. foreach($links as $link){
  14. $siteLink = 'http://theory.phphtml.net/exercises/advanced/php/parsing/zadachi-na-poetapnyj-parsing-i-metod-pauka/1/';
  15.  
  16. $site = $siteLink.pq($link)->attr('href');
  17. echo $site.'<br>';
  18. $url = curl_init();
  19. curl_setopt($url, CURLOPT_URL, $site);
  20. curl_setopt($url, CURLOPT_RETURNTRANSFER, 1);
  21. curl_setopt($url, CURLOPT_FOLLOWLOCATION, 1);
  22. $tr = curl_exec($url);
  23. $pq = phpQuery::newDocument($str);
  24. $title = $pq->find('h1')->text();
  25. $content = $pq->find('#content p')->text();
  26.  
  27. $host = 'localhost';
  28. $user = 'root';
  29. $password = '';
  30. $db_name = 'phpquery';
  31. $connect = mysqli_connect($host, $user, $password, $db_name) or die(mysqli_error($link));
  32. $query = "INSERT INTO page (id, title, content) VALUES ('', '".$title."', '".$content."')";
  33. $result = mysqli_query($connect, $query);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement