Answer the question
In order to leave comments, you need to log in
How to get a list of comments using phpQuery?
I'm trying to learn parsing with phpQuery.
Headlines, pictures I got. Here's what's interesting - on each individual page there is a block with comments.
Here is a picture with the HTML code
Question - how to get to each itemprop="author" type, etc.
So that in the end there is a similar array
Array
(
[src] => image
[title] => Name
[comments] => Array
(
[comment_name] => Name,
[comment_data]=> date,
[comment_text]=> text,
)
)
link to full pictureipic.su/img/img7/fs/kiss_88kb.1409577318.png
parser code
<?php
include('phpQuery.php');
$file = file_get_contents("http://masite/sitemap.xml");
preg_match_all("/loc>(.*)<\/loc>/Usi", $file, $link);
$count = 10;
$result = array();
for($i=0; $i<$count; $i++){
$page = $link[1][$i];
$page = file_get_contents($page);
$element =$page;
$html = phpQuery::newDocument($element);
$s = 0;
$div_card = $html->find('div.card');
foreach($div_card as $div){
$pg = pq($div);
$img_src = $pg->find("img");
$pn = pq($img_src);
$src = $pn->attr('src');
$item["src"] = $src;
$h1 = $pg->find("h1");
$title = pq($h1);
$item["title"] = $title->text();
$comments = $pg->find('.comment');
foreach($comments as $comment){
$com = pq($comment);
// пробую через jquery селектор но ничего не находит
$com_name = $com->find("span[itemprop='name']");
$name = pq($com_name);
$item["comments"]["comment_name"] = $name->text();
}
$data[] = $item;
}
unset($pg);
}
print_r($data);
Answer the question
In order to leave comments, you need to log in
Let's get a bigger picture
. So take everything between spans with regular expressions, they have different classes. I'm not strong in regular expressions, I can give an example with title$match = '/<title>(.+?)<\/title>/ism';
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question