K
K
khodos_dmitry2018-05-31 21:45:29
PHP
khodos_dmitry, 2018-05-31 21:45:29

Why can't phpQuery find links on a page?

<?php
require_once 'phpQuery/phpQuery-onefile.php';
$url = "http://www.splav-kharkov.com/main.php";
$response = file_get_contents($url);
$pq = phpQuery::newDocument($response);
$urls = $pq->find('a');
foreach ($urls as $url) {
  $pq_url = pq($url);
  $url = $pq_url->html();
  echo $url.'<br />';
}
?>

It doesn't find anything for me. Why?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yan-s, 2018-05-31
@khodos_dmitry

Invalid HTML on the patient's site.
Links are posted like this:
<b><a href='about_program.php'>text</b></a>

S
switched, 2018-06-01
@switched

The link address is contained in the attribute href, and you want to get the text between the tags
Instead:
Replace:
$url = $pq_url->attr('href');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question