Answer the question
In order to leave comments, you need to log in
phpQuery not working?
There is a code that parses the names of products on the Eldorado website (in theory, it should parse)
<?php
require_once('lib/phpQuery-onefile.php');
function get_content($url) {
$ch = curl_init($url);
curl_setopt($ch , CURLOPT_RETURNTRANSFER , true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
//curl_setopt($ch , CURLOPT_HEADER , true);
//curl_setopt ($ch , CURLOPT_USERAGENT , $_SERVER['HTTP_USER_AGENT']);
$result = curl_exec($ch);
$result = iconv('windows-1251', 'UTF-8', $result);
return $result;
}
$file = get_content('https://www.eldorado.ru/cat/4005/');
$doc = phpQuery::newDocument($file);
$forecast = $doc->find('.listGood')->children('.item');
//print_r($forecast);
foreach($forecast as $val) {
$pq = pq($val);
echo $pq->find('.itemTitle a')->text().'<br>';
}
phpQuery::unloadDocuments();
?>
$document = new Document($file);
$posts = $document->find('.listGood');
foreach($posts as $post) {
echo $post->text(), "\n";
}
Answer the question
In order to leave comments, you need to log in
Isn't it easier to take a ready-made example and adapt it?
for DOM there are all sorts of nokogiri, and for parsing - scrapy
Might be useful to someone. phpQuery didn't work for me either. There was an error in the structure of the document. In particular, I had a closing tag at the very beginning of the document. After I removed this tag from the beginning of the line, everything worked.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question