N
N
Nikita Ivanov2015-11-26 23:29:39
PHP
Nikita Ivanov, 2015-11-26 23:29:39

How to parse ads having a list of links to these ads?

Suppose there is such a page: www.farpost.ru/vladivostok/auto/sell_spare_parts/+... It has a list of links to specific ads that need to be parsed. Using this code, we get a list of the necessary ads:

<?php
require_once('simple_html_dom.php');

$maxpost = '100'; // к-во постов
$html = file_get_html('http://www.farpost.ru/vladivostok/auto/sell_spare_parts/');
$i = '0';
foreach ($html->find('tr.bull-item') as $article) { 
    $item['link'] = $article->find('a.bulletinLink', 0)->innertext; 
    $articles[] = $item; // пишем в массив
    $i++;
    if ($i == $maxpost) break; // прерывание цикла
}
for ($j = 0; $j < $maxpost; $j++) {
    echo '<div class="message">.';
    echo '<p class="text">' . $articles[$j]['link'] . '</p>';
       echo '</div>';
}
?>

As you can see, the simplehtmldom.php script is used. How to parse ads themselves?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Semyon, 2015-11-27
@skamenetskiy

It can be like this:

foreach($articles as $article) {
    $content = file_get_html($article['link']);
    $text = $content->find('p.mod__label_up_down');
    // Ну итд.
}

The principle is this. But it's better to write a class for all this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question