How to check the class on the page with phpquery?

There is a file index.html which references three other files one.html, two.html and three.html. The structure is extremely simple. In files one and three have a ul tag with the class list, and the file of two in this class and tag no.
There is another file get.php that parses those pages and checks for the class .list and displays the answer is this class or not. Here is the code:


header('Content-type: text/html; charset=UTF-8');

$start = microtime(true);



function __autoload( $className ) {require_once( "$className.php" );}

echo "<br-->".date('H:i:s')." Start parsing ";
echo '

$document = phpQuery::newDocument($page);

foreach($document->find('ul li a') as $link){

$links[] = pq($link)->attr('href');

foreach($links as $sublink){
$pageText =new Curl();
$cat_page = phpQuery::newDocument($pagenew);
$catlist = [];

foreach($cat_page as $cat_page){
if($item=pq($cat_page)->find('ul.list a')) {
 echo "class is<br>";}else{
 echo "class is not<br>";}

The problem is that in the end appears that the class is available on all three pages, though on the second page it is not. Please help to understand what is wrong here? here is what is displayed:

11:07:22 Start parsing
[0] => one.html
[1] => two.html
[2] => three.html
class is
class is
class is
July 8th 19 at 12:21
1 answer
July 8th 19 at 12:23
First, the code is shit, sorry.
Second, the design "class is" inadequate.
Third, you search for anything, not class: find('ul.list a').
Fourth, look at the Apist.
If I wrote good code, probably wouldn't here are doing and trying to learn as I can. - rodrick_Trantow commented on July 8th 19 at 12:26
: do not make excuses in front of me, better look at psr standards and install a good editor with formatting, since you are trying to learn. - meggie commented on July 8th 19 at 12:29
Didn't think to explain myself to you, I have a problem at the moment is not with formatting, but with an error in the code. Yes, I'm learning and making mistakes, if the code would work, half the problems would be solved. And your answer, I confess, I didn't help anything. Pointed out the problems - thanks, but what is the logic error and how to fix it - I received no response.. - rodrick_Trantow commented on July 8th 19 at 12:32
: I wrote that the bug is most likely here: if($item=pq($cat_page)->find('ul.list a')) { - meggie commented on July 8th 19 at 12:35
OK, thanks, like understood - rodrick_Trantow commented on July 8th 19 at 12:38

Find more questions by tags PHPParsingWeb Development