Answer the question
In order to leave comments, you need to log in
How to parse content (loop) from sites?
I want to scrape all the comments from the page.
Specified the site, the beginning and the end of the tag of one comment.
The start and stop of comments are the same.
But only the first comment is parsed for me.
How can I modify the script so that it goes through all the comments?
<?php
#откуда будем парсить информацию:
$content=file_get_contents('https://yandex.ru/maps/org/..............................');
#начало забираемого контента:
$pos=strpos($content,'review review_rating_liked');
#Отрезаем все, что идет до нужной нам позиции:
$content=substr($content,$pos);
#Таким же образом находим позицию конечной строки:
$pos=strpos($content, 'review__footer');
#Отрезаем ненужное:
$content=substr($content,0,$pos);
#Если встречается код, который нам ненужен, вырезаем его:
$content=str_replace('review review_rating_liked" itemscope="" itemprop="review" itemtype="http://schema.org/Review">','', $content);
#Выводим спарсенный текст:
echo iconv("UTF-8", "CP1251", $content), PHP_EOL;
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question