Вот весь мой код:
PHP:
скопировать код в буфер обмена
скопировать код в буфер обмена
- <?PHP
- require 'phpQuery-onefile.php';
- echo "<link rel='stylesheet' href='style.css'>";
- function parser ($url,$start,$end) {
- if ($start < $end) {
- $doc = phpQuery::newDocument($file);
- foreach ($doc->find('.product-list') as $position) {
- $position = pq($position); // Делаем $position объектов phpquery
- $articul = $position->find('.name > span:even(1)')->text(); // Тащим нужный span
- $price =$position->find('.actions .price')->html(); // Вытаскиваем цену, которая соответствует артикулу
- }
- $saveFile = 'database.html'; // Файл, для сохранения
- echo "<div class=container>";
- echo "<div class=first>";
- echo "<pre>";
- echo $articul;
- echo "</pre>";
- echo "</div>";
- echo "<div class=second>";
- echo "<pre>";
- echo $price;
- echo "</pre>";
- echo "</div>";
- echo "</div>";
- $next = $doc->find('.pagination .active')->next()->find('a')->attr('href'); // Ищем ссылку на следующую страницу сайта в пагинации
- $start++;
- parser($next, $start, $end);
- }
- }
- }
- $url = "https://www.agro-center.com.ua/combines-a/spare-parts-for-grain-harvesters/john-deere-c/?limit=100";
- $start = 0;
- $end = 1;
- parser($url,$start,$end);
- phpQuery::unloadDocuments();
- ?>