I trying to use PHPquery to scrape web-page (free-lance.ru)
Equiv code in Simple HTML Dom is working:
include('simple_html_dom.php');
$shd = str_get_html($html);
$projects = array();
$i = 0;
foreach ($shd->find('.project-preview') as $work){
$projects[$i]['name'] = $work->find('h3', 0)->children(1)->plaintext;
$i++;
}
But i need it in PHPQuery.
I tried to use something like:
include('phpQuery.php');
$pq = phpQuery::newDocument($html);
foreach ($pq->find('.project-preview') as $work){
echo 'wow';
}
But it doesn't working... sizeof($pq->find('.project-preview')) is 0
I will be very thankful for any help.
Your code looks fine. This basically equivalient code ran just fine for me.
Result:
So, the question becomes:
Update:
From your comment below, it turns out you're trying to open a html file with
newDocment()
. That just won't work. You have to usenewDocumentFile()
- or read the file contents yourself, and then usenewDocument()
, passing what you read to phpQuery.