Advertisement
Guest User

new age1

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