Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- require 'phpQuery.php';
- $url = curl_init();
- curl_setopt($url, CURLOPT_URL, "http://theory.phphtml.net/exercises/advanced/php/parsing/zadachi-na-poetapnyj-parsing-i-metod-pauka/1/index.php");
- curl_setopt($url, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($url, CURLOPT_FOLLOWLOCATION, 1);
- $str = curl_exec($url);
- $pq = phpQuery::newDocument($str);
- $links = $pq->find('#menu a');
- foreach($links as $link){
- $siteLink = 'http://theory.phphtml.net/exercises/advanced/php/parsing/zadachi-na-poetapnyj-parsing-i-metod-pauka/1/';
- $site = $siteLink.pq($link)->attr('href');
- echo $site.'<br>';
- $url = curl_init();
- curl_setopt($url, CURLOPT_URL, $site);
- curl_setopt($url, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($url, CURLOPT_FOLLOWLOCATION, 1);
- $tr = curl_exec($url);
- $pq = phpQuery::newDocument($tr);
- $title = $pq->find('h1')->text();
- $content = $pq->find('#content p')->text();
- $host = 'localhost';
- $user = 'root';
- $password = '';
- $db_name = 'phpquery';
- $connect = mysqli_connect($host, $user, $password, $db_name) or die(mysqli_error($link));
- $query = "INSERT INTO page (id, title, content) VALUES (null, '".$title."', '".$content."')";
- $result = mysqli_query($connect, $query);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement